Skip to content

Conversation

@Umjiseung
Copy link

@Umjiseung Umjiseung commented Dec 10, 2025

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"}}
)

Updated agent invocation to use structured messages and configuration.
@Umjiseung Umjiseung requested a review from lnhsingh as a code owner December 10, 2025 02:45
@github-actions github-actions bot added langchain For docs changes to LangChain oss external User is not a member of langchain-ai labels Dec 10, 2025
@github-actions github-actions bot removed the external User is not a member of langchain-ai label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant