From 07f442891c556a301a015732404be0e46d70d6c0 Mon Sep 17 00:00:00 2001 From: ki1r0 Date: Wed, 6 Aug 2025 17:52:06 +0800 Subject: [PATCH 1/5] Fix(agent): Resolved issues related to task_id generation and routing 1. Corrects a bug where the host agent generate a task_id or new task and get rejected by the DefaultRequestHandler 2. Resolved a routing issue where the same task_id from one remote agent get passed to the other, and get rejected like point 1 --- .../host_agent/routing_agent.py | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py index bbaa891b..83eb816e 100644 --- a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py +++ b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py @@ -1,3 +1,6 @@ + + + # ruff: noqa: E501 # pylint: disable=logging-fstring-interpolation import asyncio @@ -205,7 +208,7 @@ def list_remote_agents(self): ) return remote_agent_info - async def send_message( +async def send_message( self, agent_name: str, task: str, tool_context: ToolContext ): """Sends a task to remote seller agent. @@ -229,12 +232,25 @@ async def send_message( if not client: raise ValueError(f'Client not available for {agent_name}') - task_id = state['task_id'] if 'task_id' in state else str(uuid.uuid4()) - if 'context_id' in state: - context_id = state['context_id'] - else: + # Initialize the main task dictionary if it doesn't exist + if 'agent_tasks' not in state: + state['agent_tasks'] = {} + + # Get the specific task info for this agent, or an empty dict + agent_task_info = state['agent_tasks'].get(agent_name, {}) + + task_id = agent_task_info.get('task_id') + task_status = agent_task_info.get('status') + + # If a task exists and is marked as complete, we should start a new task + # by resetting the task_id. + if task_id and task_status == TaskState.completed: + task_id = None + # Also reset context_id to ensure a fresh context for the new task. context_id = str(uuid.uuid4()) + else: + context_id = agent_task_info.get('context_id') or str(uuid.uuid4()) message_id = '' metadata = {} @@ -280,7 +296,16 @@ async def send_message( print('received non-task response. Aborting get task ') return None - return send_response.root.result + task_result = send_response.root.result + + # Save the task and context IDs for this specific agent + state['agent_tasks'][agent_name] = { + 'task_id': task_result.id, + 'context_id': task_result.context_id, + 'status': task_result.status.state, + } + + return task_result def _get_initialized_routing_agent_sync() -> Agent: From 8612759a9e87dd4595050c162acbfb220c43613e Mon Sep 17 00:00:00 2001 From: ki1r0 Date: Wed, 6 Aug 2025 17:52:06 +0800 Subject: [PATCH 2/5] Fix(agent): Resolved issues related to task_id generation and routing 1. Corrects a bug where the host agent generate a task_id or new task and get rejected by the DefaultRequestHandler 2. Resolved a routing issue where the same task_id from one remote agent get passed to the other, and get rejected like point 1 --- .../host_agent/routing_agent.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py index bbaa891b..e7ed6fa4 100644 --- a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py +++ b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py @@ -1,3 +1,6 @@ + + + # ruff: noqa: E501 # pylint: disable=logging-fstring-interpolation import asyncio @@ -229,12 +232,25 @@ async def send_message( if not client: raise ValueError(f'Client not available for {agent_name}') - task_id = state['task_id'] if 'task_id' in state else str(uuid.uuid4()) - if 'context_id' in state: - context_id = state['context_id'] - else: + # Initialize the main task dictionary if it doesn't exist + if 'agent_tasks' not in state: + state['agent_tasks'] = {} + + # Get the specific task info for this agent, or an empty dict + agent_task_info = state['agent_tasks'].get(agent_name, {}) + + task_id = agent_task_info.get('task_id') + task_status = agent_task_info.get('status') + + # If a task exists and is marked as complete, we should start a new task + # by resetting the task_id. + if task_id and task_status == TaskState.completed: + task_id = None + # Also reset context_id to ensure a fresh context for the new task. context_id = str(uuid.uuid4()) + else: + context_id = agent_task_info.get('context_id') or str(uuid.uuid4()) message_id = '' metadata = {} @@ -280,7 +296,16 @@ async def send_message( print('received non-task response. Aborting get task ') return None - return send_response.root.result + task_result = send_response.root.result + + # Save the task and context IDs for this specific agent + state['agent_tasks'][agent_name] = { + 'task_id': task_result.id, + 'context_id': task_result.context_id, + 'status': task_result.status.state, + } + + return task_result def _get_initialized_routing_agent_sync() -> Agent: From e383eaea3b700ecf61e67b239b9df2cebaeb797a Mon Sep 17 00:00:00 2001 From: ki1r0 Date: Wed, 6 Aug 2025 17:58:07 +0800 Subject: [PATCH 3/5] chore: minor indentation problem --- .../airbnb_planner_multiagent/host_agent/routing_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py index 83eb816e..e7ed6fa4 100644 --- a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py +++ b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py @@ -208,7 +208,7 @@ def list_remote_agents(self): ) return remote_agent_info -async def send_message( + async def send_message( self, agent_name: str, task: str, tool_context: ToolContext ): """Sends a task to remote seller agent. From 4e60b72456e3128adc99238af1dcd045d4ae1966 Mon Sep 17 00:00:00 2001 From: ki1r0 Date: Thu, 7 Aug 2025 01:55:20 +0800 Subject: [PATCH 4/5] chore: add missing import --- .../agents/airbnb_planner_multiagent/host_agent/routing_agent.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py index e7ed6fa4..443044a1 100644 --- a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py +++ b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py @@ -21,6 +21,7 @@ SendMessageResponse, SendMessageSuccessResponse, Task, + TaskState, ) from agents.airbnb_planner_multiagent.host_agent.remote_agent_connection import ( RemoteAgentConnections, From 41d30257250508e0814669c0eeddd6284f3549e1 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Thu, 7 Aug 2025 16:00:58 +0100 Subject: [PATCH 5/5] Formatting --- .../host_agent/routing_agent.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py index 443044a1..76d0ffb7 100644 --- a/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py +++ b/samples/python/agents/airbnb_planner_multiagent/host_agent/routing_agent.py @@ -1,6 +1,3 @@ - - - # ruff: noqa: E501 # pylint: disable=logging-fstring-interpolation import asyncio @@ -237,7 +234,7 @@ async def send_message( # Initialize the main task dictionary if it doesn't exist if 'agent_tasks' not in state: state['agent_tasks'] = {} - + # Get the specific task info for this agent, or an empty dict agent_task_info = state['agent_tasks'].get(agent_name, {}) @@ -298,14 +295,14 @@ async def send_message( return None task_result = send_response.root.result - + # Save the task and context IDs for this specific agent state['agent_tasks'][agent_name] = { 'task_id': task_result.id, 'context_id': task_result.context_id, 'status': task_result.status.state, } - + return task_result