Skip to content

Fix agent message length #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions examples/langgraph-agent/agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"\n",
"## Install dependencies\n",
"```shell\n",
"pip install zep-cloud langchain-openai langgraph ipywidgets\n",
"pip install zep-cloud langchain-openai langgraph ipywidgets dotenv\n",
"```"
]
},
Expand Down Expand Up @@ -236,6 +236,21 @@
" {memory.context}\"\"\"\n",
" )\n",
"\n",
" # Truncate the chat history to keep the state from growing unbounded\n",
" # In this example, we going to keep the state small for demonstration purposes\n",
" # We'll use Zep's Facts to maintain conversation context\n",
" state[\"messages\"] = trim_messages(\n",
" state[\"messages\"],\n",
" strategy=\"last\",\n",
" token_counter=len,\n",
" max_tokens=3,\n",
" start_on=\"human\",\n",
" end_on=(\"human\", \"tool\"),\n",
" include_system=True,\n",
" )\n",
"\n",
" logger.info(f\"Messages in state: {state['messages']}\")\n",
"\n",
" messages = [system_message] + state[\"messages\"]\n",
"\n",
" response = await llm.ainvoke(messages)\n",
Expand All @@ -255,21 +270,6 @@
" messages=messages_to_save,\n",
" )\n",
"\n",
" # Truncate the chat history to keep the state from growing unbounded\n",
" # In this example, we going to keep the state small for demonstration purposes\n",
" # We'll use Zep's Facts to maintain conversation context\n",
" state[\"messages\"] = trim_messages(\n",
" state[\"messages\"],\n",
" strategy=\"last\",\n",
" token_counter=len,\n",
" max_tokens=3,\n",
" start_on=\"human\",\n",
" end_on=(\"human\", \"tool\"),\n",
" include_system=True,\n",
" )\n",
"\n",
" logger.info(f\"Messages in state: {state['messages']}\")\n",
"\n",
" return {\"messages\": [response]}"
]
},
Expand Down