a2aproject / a2aproject/a2a-samples

TaskNotFoundError when 'multiagent' sample code sends non-null task_id to a remote agent running on a separate task store

Đang mở
#310 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Jupyter Notebook
Star
1.8k
Fork
751
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### What happened?

`samples/python/hosts/multiagent
/host_agent.py` has a tool called `send_message` that allows it to delegate sub tasks to remote agents, and it has logic in it that sets a task_id if the sub task happens to be any sub task other than the first one.

For example, if the host_agent determines that it needs to do three calls to remote agents to satisfy the user's query (imagine there are individual remote agents that handle basic math operations like addition, subtraction, multiplication, and division, and the user's query is `What is 1+(2*3) - 7?`), the first remote agent call will set task_id to None, and the second and third calls will set task_id to the uuid generated by the creation of the first call to a remote agent.

The code that does this task_id setting, if one exists, is here: https://github.com/a2aproject/a2a-samples/blob/main/samples/python/hosts/multiagent/host_agent.py#L185

```python
task_id = state.get('task_id', None)
context_id = state.get('context_id', None)
message_id = state.get('message_id', None)
task: Task
if not message_id:
message_id = str(uuid.uuid4())
request: MessageSendParams = MessageSendParams(
id=str(uuid.uuid4()),
message=Message(
role='user',
parts=[TextPart(text=message)],
message_id=message_id,
context_id=context_id,
task_id=task_id,
),
```

The issue I'm running into is similar to this one: https://github.com/a2aproject/a2a-samples/issues/304

If I run the demo UI (https://github.com/a2aproject/a2a-samples/tree/main/demo/ui), which uses this host_agent code (https://github.com/a2aproject/a2a-samples/tree/main/samples/python/hosts/multiagent) under the covers, and I register one or more remote agents, running in their own runtimes, and I send a request to the host_agent that causes it to invoke the send_message tool more than once, when task_id is set to anything other than `None`, I get the following error in my remote agent code:

https://github.com/a2aproject/a2a-python/blob/dec4b487514db6cbb25f0c6fa7e1275a1ab0ba71/src/a2a/server/request_handlers/default_request_handler.py#L203-L207

```python
elif params.message.task_id:
raise ServerError(
error=TaskNotFoundError(
message=f'Task {params.message.task_id} was specified but does not exist'
)
)
```

Because my host agent and my remote agent don't share a task store, the remote agent dies if it receives a task id that was generated by the host agent in the request.

## Questions:

* Is this sample host_agent code meant to only work when all agents share a task store, or all agents literally run on the same server?

* Or perhaps is this a bug where the a2a protocol has progressed to a certain point about the management of sessions, context, task_id's, etc. such that the sample code just has not been updated to match the current state of the protocol?

### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.