Skip to content

Human in the loop error #115

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
Ankur-Kumar222 opened this issue Apr 20, 2025 · 0 comments
Open

Human in the loop error #115

Ankur-Kumar222 opened this issue Apr 20, 2025 · 0 comments

Comments

@Ankur-Kumar222
Copy link

  1. I've created a supervisor architecture with a bunch of sub agents.
  2. Each sub agent is a pre-built create_react_agent with a tool called human input.
  3. On LangGraph studio, the agent works perfectly.
  4. 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 {}.
  5. 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",
            )
        ]
    }

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant