Open
Description
- I've created a supervisor architecture with a bunch of sub agents.
- Each sub agent is a pre-built create_react_agent with a tool called human input.
- On LangGraph studio, the agent works perfectly.
- When run on the agent-chat-ui, the sub agent's assistant calls the human input tool but does not wait for the user's input and instead returns an empty {}.
- This happens multiple times until the agent gives up and goes back to the supervisor.
from langgraph.types import interrupt
from langgraph.prebuilt import create_react_agent
from langgraph.prebuilt.interrupt import (
ActionRequest,
HumanInterrupt,
HumanInterruptConfig,
HumanResponse,
)
import os
from langchain_openai import ChatOpenAI
from langgraph.graph import MessagesState
from langchain_core.messages import AIMessage, HumanMessage
from Agents.promptTemplates import personal_agent_system_message
class PersonalState(MessagesState):
pass
class SupervisorState(MessagesState):
next: str
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
LLM_MODEL = os.environ['LLM_MODEL']
llm = ChatOpenAI(model=LLM_MODEL, api_key=OPENAI_API_KEY, temperature=0, stream_usage=True)
def human_input(state: PersonalState):
"""
This tool is used to get user input.
"""
tool_call = state["messages"][-1].tool_calls[0]
action_request = ActionRequest(
action=tool_call['name'],
args=tool_call['args'],
)
interrupt_config = HumanInterruptConfig(
allow_respond=True,
)
description = (
"Type your response here..."
)
request = HumanInterrupt(
action_request=action_request, config=interrupt_config, description=description
)
response: HumanResponse = interrupt([request])[0]
if response.get("type") == "response":
return {
"messages": [
HumanMessage(
content=response.get('args'),
name="User",
)
]
}
def database_update(state: PersonalState):
"""
This tool is used to update the database with user information.
"""
print("Updating database with the following information:")
print(state["messages"][-1].content)
return {
"messages": [
AIMessage(
content="Database updated successfully!",
name="personalAgent",
)
]
}
tools = [human_input, database_update]
personalAgent = create_react_agent(llm, tools=tools, state_modifier = personal_agent_system_message)
def personal_node(state: SupervisorState):
result = personalAgent.invoke({'messages': state["messages"][-1]})
last_message = result["messages"][-1]
return {
"messages": [
AIMessage(
content=last_message.content,
name="personalAgent",
)
]
}
Metadata
Metadata
Assignees
Labels
No labels