Skip to content

I am trying to access the data from State in a multi-agent system, however the last state update is missing #1238

Open
@dpurandare

Description

@dpurandare

I am trying to access the last state update and the state variable 'key5' however the behavior is unpredictable. Sometimes the value is available and sometimes not. I have seen sometimes the value is partially updated. I am wrapping the agent code behind the FastAPI. Here is the representative code sample.


agent1 = Agent(
...
output_key = 'key1'
)
...
agent5 = Agent(
...
output_key = 'key5'
)

workslow_sequence_agent = SequentialAgent(
sub_agents=[
agent1,
agent2,
agent3,
agent4,
agent5
],
)

workflow_agent = Agent(
----
sub_agents=[workflow_sequence_agent],
output_key='workflow_output',
)

async def call_agent_async(query: str, runner, user_id, session_id):
# Prepare the user's message in ADK format
content = types.Content(role='user', parts=[types.Part(text=query)])

final_response_text = "Agent did not produce a final response." # Default

async for event in runner.run_async(user_id=user_id, session_id=session_id, new_message=content):
    if event.is_final_response():
        if event.content and event.content.parts:
            # Assuming text response in the first part
            final_response_text = event.content.parts[0].text
        elif event.actions and event.actions.escalate: # Handle potential errors/escalations
            final_response_text = f"Agent escalated: {event.error_message or 'No specific message.'}"
return final_response_text

@app.get('/workflow/')
async def workflow(input_info: str):
if input_info == "":
return {"message": "Please provide the input"}

root_agent = workflow_agent

# Session and Runner
session_service = InMemorySessionService()
session = session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)

final_response_text = await call_agent_async(input_info, runner, USER_ID, SESSION_ID)
# await sleep(2)  # Simulate some processing delay
updated_session = session_service.get_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)   
stateinfo = updated_session.state
return {"message": stateinfo}

I tried the synchronous execution as well and found the behavior to be the same.
Trying to understand if this is a bug or I did something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot_triagedcoreIssues related to the core interface and implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions