-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathagent_executor.py
More file actions
49 lines (39 loc) · 1.75 KB
/
agent_executor.py
File metadata and controls
49 lines (39 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from abc import ABC, abstractmethod
from typing import Any
from a2a.server.agent_execution.context import RequestContext
from a2a.server.events.event_queue import EventQueue
class AgentExecutor(ABC):
"""Agent Executor interface.
Implementations of this interface contain the core logic of the agent,
executing tasks based on requests and publishing updates to an event queue.
"""
@abstractmethod
async def execute(
self,
context: RequestContext,
event_queue: EventQueue,
request_handler: Any,
) -> None:
"""Execute the agent's logic for a given request context.
The agent should read necessary information from the `context` and
publish `Task` or `Message` events, or `TaskStatusUpdateEvent` /
`TaskArtifactUpdateEvent` to the `event_queue`. This method should
return once the agent's execution for this request is complete or
yields control (e.g., enters an input-required state).
Args:
context: The request context containing the message, task ID, etc.
event_queue: The queue to publish events to.
request_handler: The request handler that is executing the agent.
"""
@abstractmethod
async def cancel(
self, context: RequestContext, event_queue: EventQueue
) -> None:
"""Request the agent to cancel an ongoing task.
The agent should attempt to stop the task identified by the task_id
in the context and publish a `TaskStatusUpdateEvent` with state
`TaskState.canceled` to the `event_queue`.
Args:
context: The request context containing the task ID to cancel.
event_queue: The queue to publish the cancellation status update to.
"""