RunnableConfig in Tools with Legacy AgentExecutor vs. Graph AgentExecutor #25396
Replies: 1 comment 3 replies
-
The To achieve similar functionality, you should migrate to the Graph-based React Agent, which fully supports
Here is an example of how to migrate your code to use the Graph-based React Agent: import asyncio
import os
import random
from langchain import hub
from langchain.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
model = ChatOpenAI(...)
@tool
def where_cat_is_hiding(config: RunnableConfig) -> str:
print("Runnable Config:", config)
return random.choice(["under the bed", "on the shelf"])
@tool
def get_items(place: str, config: RunnableConfig) -> str:
print("Runnable Config:", config)
if "bed" in place:
return "socks, shoes and dust bunnies"
if "shelf" in place:
return "books, pencils and pictures"
else:
return "cat snacks"
tools = [get_items, where_cat_is_hiding]
graph = create_react_agent(model, tools=tools)
def print_stream(stream):
for s in stream:
message = s["messages"][-1]
if isinstance(message, tuple):
print(message)
else:
message.pretty_print()
async def main():
inputs = {"messages": [("user", "what's items are located where the cat is hiding?")]}
print_stream(graph.stream(inputs, stream_mode="values", config={"configurable": {"username": "test"}}))
asyncio.run(main()) By following these steps, you can ensure compatibility with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to use the RunnableConfig in the Tool, but it does not work with the leagcy AgentExecutor. It works fine with the Graph based react Agent.
I can see the content of RunnableConfig with Graphs. Is this feature not going to be supported with Legacy AgentExecutor?
System Info
langchain==0.2.13
langchain-anthropic==0.1.22
langchain-aws==0.1.16
langchain-community==0.2.12
langchain-core==0.2.30
langchain-experimental==0.0.64
langchain-ollama==0.1.0rc0
langchain-openai==0.1.21
langchain-text-splitters==0.2.1
langchainhub==0.1.21
langdetect==1.0.9
langgraph==0.2.3
langgraph-checkpoint==1.0.2
langserve==0.2.2
langsmith==0.1.99
Beta Was this translation helpful? Give feedback.
All reactions