From 3111f21431012eaa72bcab1a7f0e3b5a17b53c7c Mon Sep 17 00:00:00 2001 From: Andres Suarez <23503930+glicerico@users.noreply.github.com> Date: Tue, 27 May 2025 15:06:06 -0600 Subject: [PATCH 1/2] Relocate message_trimming to have proper message length --- examples/langgraph-agent/agent.ipynb | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/langgraph-agent/agent.ipynb b/examples/langgraph-agent/agent.ipynb index 4c8ff1e3..e808a03c 100644 --- a/examples/langgraph-agent/agent.ipynb +++ b/examples/langgraph-agent/agent.ipynb @@ -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", @@ -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]}" ] }, From 8294e57604424426f0f40944ac31ee0311e728f0 Mon Sep 17 00:00:00 2001 From: Andres Suarez <23503930+glicerico@users.noreply.github.com> Date: Tue, 27 May 2025 15:06:49 -0600 Subject: [PATCH 2/2] Install dotenv to avoid errors --- examples/langgraph-agent/agent.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/langgraph-agent/agent.ipynb b/examples/langgraph-agent/agent.ipynb index e808a03c..f44518d7 100644 --- a/examples/langgraph-agent/agent.ipynb +++ b/examples/langgraph-agent/agent.ipynb @@ -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", "```" ] },