[PR #1825] [MERGED] fix(docs): Update example code in Test Docs #1884

Closed
opened 2026-02-17 17:22:50 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/docs/pull/1825
Author: @Umjiseung
Created: 12/9/2025
Status: Merged
Merged: 1/23/2026
Merged by: @mdrxy

Base: mainHead: patch-1


📝 Commits (6)

  • f3e17a9 Refactor agent.invoke to use structured input
  • 6a0a5d5 Merge branch 'main' into patch-1
  • a61c5a4 Merge branch 'main' into patch-1
  • e061caf Merge branch 'main' into patch-1
  • a18843d Merge branch 'main' into patch-1
  • 322c7a1 Merge branch 'main' into patch-1

📊 Changes

1 file changed (+8 additions, -2 deletions)

View changed files

📝 src/oss/langchain/test.mdx (+8 -2)

📄 Description

Updated agent invocation to use structured messages and configuration

Overview

This PR updates the documentation example for agent.invoke() to correctly demonstrate:

  • Passing structured messages using {"messages": [HumanMessage(...)]}
  • Passing configuration using
    config={"configurable": {"thread_id": "<session-id>"}}
  • Proper usage of checkpoint-based memory with InMemorySaver

Previously, the example omitted or incorrectly used the config argument, which caused confusion and errors when users attempted to maintain session-based memory.
This update provides a fully functional example that aligns with current agent APIs.


Type of change

Type: Update existing documentation


Related issues/PRs

None


Checklist

  • I have read the contributing guidelines
  • I have tested my changes locally using docs dev
  • All code examples have been tested and confirmed working
  • I have used root-relative paths for internal links
  • I have updated navigation in src/docs.json if needed

Additional notes

This update ensures that the documentation demonstrates the correct pattern for invoking agents that use checkpointing or session-based memory. Without a configurable.thread_id, each call creates a new memory session, making it impossible to persist user context.

The updated, working example is shown below:

from langgraph.checkpoint.memory import InMemorySaver
from langchain.agents import create_agent
from langchain_core.messages import HumanMessage

checkpointer = InMemorySaver()

agent = create_agent(
    model="google_genai:gemini-2.5-flash-lite",
    tools=[],
    checkpointer=checkpointer
)

# First invocation
agent.invoke(
    {"messages": [HumanMessage(content="I live in Sydney, Australia")]},
    config={"configurable": {"thread_id": "session-1"}}
)

# Second invocation: the first message is persisted (Sydney location), so the model returns GMT+10 time
agent.invoke(
    {"messages": [HumanMessage(content="What's my local time?")]},
    config={"configurable": {"thread_id": "session-1"}}
)


---

<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/docs/pull/1825 **Author:** [@Umjiseung](https://github.com/Umjiseung) **Created:** 12/9/2025 **Status:** ✅ Merged **Merged:** 1/23/2026 **Merged by:** [@mdrxy](https://github.com/mdrxy) **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (6) - [`f3e17a9`](https://github.com/langchain-ai/docs/commit/f3e17a9ae103626ec44ef350fd186dcf92978de4) Refactor agent.invoke to use structured input - [`6a0a5d5`](https://github.com/langchain-ai/docs/commit/6a0a5d513bdc95b837a89b4566bc1aa96ef47407) Merge branch 'main' into patch-1 - [`a61c5a4`](https://github.com/langchain-ai/docs/commit/a61c5a466a98193b6929fdd00e89c11222fe14e6) Merge branch 'main' into patch-1 - [`e061caf`](https://github.com/langchain-ai/docs/commit/e061caf5a9e69f13b41ad61f2d56413a0ea17a3a) Merge branch 'main' into patch-1 - [`a18843d`](https://github.com/langchain-ai/docs/commit/a18843d967263d4e9c2d660529a0fa334b2cbb13) Merge branch 'main' into patch-1 - [`322c7a1`](https://github.com/langchain-ai/docs/commit/322c7a11d6fa369c5c9fe70cd0e81497ac68caec) Merge branch 'main' into patch-1 ### 📊 Changes **1 file changed** (+8 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/oss/langchain/test.mdx` (+8 -2) </details> ### 📄 Description # Updated agent invocation to use structured messages and configuration ## Overview This PR updates the documentation example for `agent.invoke()` to correctly demonstrate: - Passing **structured messages** using `{"messages": [HumanMessage(...)]}` - Passing **configuration** using `config={"configurable": {"thread_id": "<session-id>"}}` - Proper usage of **checkpoint-based memory** with `InMemorySaver` Previously, the example omitted or incorrectly used the `config` argument, which caused confusion and errors when users attempted to maintain session-based memory. This update provides a fully functional example that aligns with current agent APIs. --- ## Type of change **Type:** Update existing documentation --- ## Related issues/PRs None --- ## Checklist - [x] I have read the contributing guidelines - [x] I have tested my changes locally using `docs dev` - [x] All code examples have been tested and confirmed working - [x] I have used root-relative paths for internal links - [x] I have updated navigation in `src/docs.json` if needed --- ## Additional notes This update ensures that the documentation demonstrates the correct pattern for invoking agents that use checkpointing or session-based memory. Without a `configurable.thread_id`, each call creates a new memory session, making it impossible to persist user context. The updated, working example is shown below: ```python from langgraph.checkpoint.memory import InMemorySaver from langchain.agents import create_agent from langchain_core.messages import HumanMessage checkpointer = InMemorySaver() agent = create_agent( model="google_genai:gemini-2.5-flash-lite", tools=[], checkpointer=checkpointer ) # First invocation agent.invoke( {"messages": [HumanMessage(content="I live in Sydney, Australia")]}, config={"configurable": {"thread_id": "session-1"}} ) # Second invocation: the first message is persisted (Sydney location), so the model returns GMT+10 time agent.invoke( {"messages": [HumanMessage(content="What's my local time?")]}, config={"configurable": {"thread_id": "session-1"}} ) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-17 17:22:50 -05:00
yindo closed this issue 2026-02-17 17:22:50 -05:00
yindo changed title from [PR #1825] fix(docs): Update example code in Test Docs to [PR #1825] [MERGED] fix(docs): Update example code in Test Docs 2026-06-05 18:15:28 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#1884