distributed-a2a 0.1.5rc17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- distributed_a2a/__init__.py +7 -0
- distributed_a2a/agent.py +61 -0
- distributed_a2a/client.py +110 -0
- distributed_a2a/executors.py +82 -0
- distributed_a2a/model.py +59 -0
- distributed_a2a/registry.py +18 -0
- distributed_a2a/server.py +87 -0
- distributed_a2a-0.1.5rc17.dist-info/METADATA +114 -0
- distributed_a2a-0.1.5rc17.dist-info/RECORD +12 -0
- distributed_a2a-0.1.5rc17.dist-info/WHEEL +5 -0
- distributed_a2a-0.1.5rc17.dist-info/licenses/LICENSE +21 -0
- distributed_a2a-0.1.5rc17.dist-info/top_level.txt +1 -0
distributed_a2a/agent.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from a2a.types import TaskState
|
|
4
|
+
from langchain.agents import create_agent
|
|
5
|
+
from langchain_core.runnables import RunnableConfig
|
|
6
|
+
from langchain_core.tools import BaseTool
|
|
7
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
from .model import get_model, AgentConfig, LLMConfig
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AgentResponse(BaseModel):
|
|
14
|
+
status: Literal[TaskState.rejected, TaskState.completed, TaskState.rejected, TaskState.failed] = Field(
|
|
15
|
+
description=(
|
|
16
|
+
f'You should select status as {TaskState.rejected} for requests that fall outside your area of expertise.'
|
|
17
|
+
f'You should select status as {TaskState.completed} if the request is fully addressed and no further input is needed. '
|
|
18
|
+
f'You should select status as {TaskState.input_required} if you need more information from the user or are asking a clarifying question. '
|
|
19
|
+
f'You should select status as {TaskState.failed} if an error occurred or the request cannot be fulfilled.'
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
class RoutingResponse(AgentResponse):
|
|
24
|
+
agent_card: str = Field(description="The stringified json of the agent card to be returned to the user")
|
|
25
|
+
|
|
26
|
+
class StringResponse(AgentResponse):
|
|
27
|
+
response: str = Field(description="The main response to be returned to the user")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class StatusAgent[ResponseT: AgentResponse]:
|
|
31
|
+
|
|
32
|
+
def __init__(self, llm_config: LLMConfig, name: str, system_prompt: str, api_key: str, is_routing: bool, tools: list[BaseTool]):
|
|
33
|
+
response_format: type[AgentResponse]
|
|
34
|
+
if is_routing:
|
|
35
|
+
response_format = RoutingResponse
|
|
36
|
+
else:
|
|
37
|
+
response_format = StringResponse
|
|
38
|
+
|
|
39
|
+
self.agent = create_agent(
|
|
40
|
+
get_model(api_key=api_key,
|
|
41
|
+
model=llm_config.model,
|
|
42
|
+
base_url=llm_config.base_url,
|
|
43
|
+
reasoning_effort=llm_config.reasoning_effort),
|
|
44
|
+
tools=tools,
|
|
45
|
+
checkpointer=MemorySaver(), # TODO replace by dynamodb
|
|
46
|
+
system_prompt=system_prompt,
|
|
47
|
+
response_format=response_format,
|
|
48
|
+
name=name
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
async def __call__(self, message: str, context_id: str = None) -> ResponseT:
|
|
52
|
+
config: RunnableConfig = RunnableConfig(configurable={'thread_id': context_id})
|
|
53
|
+
response = await self.agent.ainvoke(LangGraphMessage(message), config)
|
|
54
|
+
return response['structured_response']
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class LangGraphMessage(BaseModel):
|
|
58
|
+
messages: list[tuple[Literal['user'], str]]
|
|
59
|
+
|
|
60
|
+
def __init__(self, messages: str):
|
|
61
|
+
super().__init__(messages=[("user", messages)])
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import time
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from a2a.client import ClientConfig, ClientFactory, A2ACardResolver, ClientEvent
|
|
7
|
+
from a2a.client import create_text_message_object
|
|
8
|
+
from a2a.types import (
|
|
9
|
+
AgentCard,
|
|
10
|
+
Message, TaskQueryParams, Task, Artifact, Part, TextPart
|
|
11
|
+
)
|
|
12
|
+
from a2a.types import TaskState
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RemoteAgentConnection:
|
|
16
|
+
"""A class to hold the connections to the remote agents."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, agent_card: AgentCard, client: httpx.AsyncClient):
|
|
19
|
+
client_config = ClientConfig(
|
|
20
|
+
httpx_client=client,
|
|
21
|
+
supported_transports=[agent_card.preferred_transport],
|
|
22
|
+
streaming=agent_card.capabilities.streaming,
|
|
23
|
+
polling=True
|
|
24
|
+
)
|
|
25
|
+
client_factory = ClientFactory(config=client_config)
|
|
26
|
+
self.agent_client = client_factory.create(agent_card)
|
|
27
|
+
|
|
28
|
+
async def _send_message_to_agent(self, message_request: Message) -> Task:
|
|
29
|
+
|
|
30
|
+
responses: list[ClientEvent] = []
|
|
31
|
+
async for response in self.agent_client.send_message(message_request):
|
|
32
|
+
responses.append(response)
|
|
33
|
+
|
|
34
|
+
task_response: Task | None = None
|
|
35
|
+
match responses:
|
|
36
|
+
case [(task, _)]:
|
|
37
|
+
task_response = task
|
|
38
|
+
case _:
|
|
39
|
+
raise Exception("Wrong response format")
|
|
40
|
+
return task_response
|
|
41
|
+
|
|
42
|
+
async def _get_task(self, task_id: str) -> Task:
|
|
43
|
+
query_params: TaskQueryParams = TaskQueryParams(id=task_id)
|
|
44
|
+
response: Task = await self.agent_client.get_task(query_params)
|
|
45
|
+
return response
|
|
46
|
+
|
|
47
|
+
async def send_message(self, message_to_send: str, context_id, task_id: None | str = None,
|
|
48
|
+
count=0) -> str | AgentCard:
|
|
49
|
+
message: Message = create_text_message_object(content=message_to_send)
|
|
50
|
+
message.message_id = str(uuid4())
|
|
51
|
+
message.context_id = context_id
|
|
52
|
+
|
|
53
|
+
response: Task
|
|
54
|
+
if task_id is None:
|
|
55
|
+
response = await self._send_message_to_agent(message)
|
|
56
|
+
else:
|
|
57
|
+
response = await self._get_task(task_id)
|
|
58
|
+
|
|
59
|
+
task_state = response.status.state
|
|
60
|
+
if task_state == TaskState.working or task_state == TaskState.submitted:
|
|
61
|
+
if count < 20:
|
|
62
|
+
time.sleep(1)
|
|
63
|
+
return await self.send_message(message_to_send, context_id, response.id, count + 1)
|
|
64
|
+
else:
|
|
65
|
+
raise Exception("Timeout waiting for agent to respond")
|
|
66
|
+
|
|
67
|
+
if task_state == TaskState.failed:
|
|
68
|
+
raise Exception("A2ATaskFailed")
|
|
69
|
+
elif task_state == TaskState.auth_required:
|
|
70
|
+
raise Exception("A2ATaskAuthRequired")
|
|
71
|
+
|
|
72
|
+
match response.artifacts:
|
|
73
|
+
case [Artifact(name='target_agent', parts=[Part(root=TextPart(text=agent_card))])]:
|
|
74
|
+
return AgentCard(**json.loads(agent_card))
|
|
75
|
+
case [Artifact(name='current_result', parts=[Part(root=TextPart(text=result))])]:
|
|
76
|
+
return result
|
|
77
|
+
case _:
|
|
78
|
+
raise Exception("Wrong response format")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
MAX_RECURSION_DEPTH = 10
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class RoutingA2AClient:
|
|
85
|
+
def __init__(self, initial_url: str):
|
|
86
|
+
self.url = initial_url
|
|
87
|
+
self.client = httpx.AsyncClient()
|
|
88
|
+
self.current_card: AgentCard | None = None
|
|
89
|
+
|
|
90
|
+
async def fetch_current_card(self):
|
|
91
|
+
card_resolver = A2ACardResolver(
|
|
92
|
+
self.client, self.url
|
|
93
|
+
)
|
|
94
|
+
self.current_card = (
|
|
95
|
+
await card_resolver.get_agent_card()
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
async def send_message(self, message: str, context_id: str, depth: int = 0) -> str:
|
|
99
|
+
if depth > MAX_RECURSION_DEPTH:
|
|
100
|
+
raise Exception("Maximum recursion depth exceeded. This is likely due to an infinite loop in your agent.")
|
|
101
|
+
if self.current_card is None:
|
|
102
|
+
await self.fetch_current_card()
|
|
103
|
+
|
|
104
|
+
agent_connection = RemoteAgentConnection(self.current_card, self.client)
|
|
105
|
+
|
|
106
|
+
agent_response: str | AgentCard = await agent_connection.send_message(message, context_id)
|
|
107
|
+
if isinstance(agent_response, AgentCard):
|
|
108
|
+
self.current_card = agent_response
|
|
109
|
+
return await self.send_message(message, context_id, depth + 1)
|
|
110
|
+
return agent_response
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from a2a.server.agent_execution import AgentExecutor, RequestContext
|
|
6
|
+
from a2a.server.events import EventQueue
|
|
7
|
+
from a2a.types import TaskStatusUpdateEvent, TaskStatus, TaskState, TaskArtifactUpdateEvent, Artifact
|
|
8
|
+
from a2a.utils import new_text_artifact
|
|
9
|
+
from langchain_core.tools import BaseTool
|
|
10
|
+
|
|
11
|
+
from .agent import StatusAgent, RoutingResponse, StringResponse
|
|
12
|
+
from .model import AgentConfig
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
ROUTING_SYSTEM_PROMPT = """
|
|
17
|
+
You are a helpful routing assistant which routes user requests to specialized remote agents. Your main task is to:
|
|
18
|
+
1. look up available agents via their A2A agent cards
|
|
19
|
+
2. select the best matching agent for the user query
|
|
20
|
+
3. return the matching agent card for that agent."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class RoutingAgentExecutor(AgentExecutor):
|
|
24
|
+
|
|
25
|
+
def __init__(self, agent_config: AgentConfig, routing_tool: BaseTool, tools: list[BaseTool] | None = None):
|
|
26
|
+
super().__init__()
|
|
27
|
+
api_key = os.environ.get(agent_config.agent.llm.api_key_env)
|
|
28
|
+
self.agent = StatusAgent[StringResponse](
|
|
29
|
+
llm_config=agent_config.agent.llm,
|
|
30
|
+
system_prompt=agent_config.agent.system_prompt,
|
|
31
|
+
name=agent_config.agent.card.name,
|
|
32
|
+
api_key=api_key,
|
|
33
|
+
is_routing=False,
|
|
34
|
+
tools=[] if tools is None else tools,
|
|
35
|
+
)
|
|
36
|
+
self.routing_agent = StatusAgent[RoutingResponse](
|
|
37
|
+
llm_config=agent_config.agent.llm,
|
|
38
|
+
system_prompt=ROUTING_SYSTEM_PROMPT,
|
|
39
|
+
name="Router",
|
|
40
|
+
api_key=api_key,
|
|
41
|
+
is_routing=True,
|
|
42
|
+
tools=[routing_tool]
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
|
|
46
|
+
raise NotImplementedError
|
|
47
|
+
|
|
48
|
+
async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
|
|
49
|
+
# set status to processing
|
|
50
|
+
await event_queue.enqueue_event(TaskStatusUpdateEvent(status=TaskStatus(state=TaskState.working),
|
|
51
|
+
final=False,
|
|
52
|
+
context_id=context.context_id,
|
|
53
|
+
task_id=context.task_id))
|
|
54
|
+
agent_response: StringResponse = await self.agent(message=context.get_user_input(),
|
|
55
|
+
context_id=context.context_id)
|
|
56
|
+
|
|
57
|
+
artifact: Artifact
|
|
58
|
+
if agent_response.status == TaskState.rejected:
|
|
59
|
+
agent_response: RoutingResponse = await self.routing_agent(message=context.get_user_input(),
|
|
60
|
+
context_id=context.context_id)
|
|
61
|
+
agent_name: str = json.loads(agent_response.agent_card)["name"]
|
|
62
|
+
logger.info(f"Request with id {context.context_id} got rejected and will be rerouted to a '{agent_name}'.",
|
|
63
|
+
extra={"card": agent_response.agent_card})
|
|
64
|
+
artifact = new_text_artifact(name='target_agent', description='New target agent for request.',
|
|
65
|
+
text=agent_response.agent_card)
|
|
66
|
+
else:
|
|
67
|
+
logger.info(f"Request with id {context.context_id} was successfully processed by agent.")
|
|
68
|
+
artifact = new_text_artifact(name='current_result', description='Result of request to agent.',
|
|
69
|
+
text=agent_response.response)
|
|
70
|
+
|
|
71
|
+
# publish actual result
|
|
72
|
+
await event_queue.enqueue_event(TaskArtifactUpdateEvent(append=False,
|
|
73
|
+
context_id=context.context_id,
|
|
74
|
+
task_id=context.task_id,
|
|
75
|
+
last_chunk=True,
|
|
76
|
+
artifact=artifact))
|
|
77
|
+
# set and publish the final status
|
|
78
|
+
await event_queue.enqueue_event(TaskStatusUpdateEvent(status=TaskStatus(
|
|
79
|
+
state=TaskState(agent_response.status)),
|
|
80
|
+
final=True,
|
|
81
|
+
context_id=context.context_id,
|
|
82
|
+
task_id=context.task_id))
|
distributed_a2a/model.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import List, Any
|
|
3
|
+
|
|
4
|
+
from langchain_core.language_models import BaseChatModel
|
|
5
|
+
from langchain_openai import ChatOpenAI
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SkillConfig(BaseModel):
|
|
10
|
+
id: str = Field(description="The id of the skill e.g. weather")
|
|
11
|
+
name: str = Field(description="The name of the skill e.g. weather")
|
|
12
|
+
description: str = Field(description="A short description of the skill")
|
|
13
|
+
tags: List[str] = Field(description="The tags associated with the skill")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class LLMConfig(BaseModel):
|
|
17
|
+
base_url: str = Field(description="The base url of the LLM provider")
|
|
18
|
+
model: str = Field(description="The model to use for the LLM e.g. gpt-3.5-turbo")
|
|
19
|
+
api_key_env: str = Field(description="The environment variable containing the api key for the LLM provider")
|
|
20
|
+
reasoning_effort: str = Field(description="The reasoning effort to use for the LLM e.g. high", default="high")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CardConfig(BaseModel):
|
|
24
|
+
name: str = Field(description="The name of the agent" )
|
|
25
|
+
description: str = Field(description="A short description of the agent")
|
|
26
|
+
version: str = Field(description="The version of the agent")
|
|
27
|
+
default_input_modes: List[str] = Field(description="The default input modes supported by the agent", default=["text","text/plaintext"])
|
|
28
|
+
default_output_modes: List[str] = Field(description="The default output modes supported by the agent", default=["text","text/plaintext"])
|
|
29
|
+
preferred_transport_protocol: str = Field(description="The preferred transport protocol for the agent", default="HTTP+JSON")
|
|
30
|
+
url: str = Field(description="The url of the agent")
|
|
31
|
+
skills: List[SkillConfig] = Field(description="The skills supported by the agent", default=[])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AgentItem(BaseModel):
|
|
35
|
+
card: CardConfig = Field(description="The agent card configuration node")
|
|
36
|
+
llm: LLMConfig = Field(description="The LLM configuration node")
|
|
37
|
+
system_prompt: str = Field(description="The system prompt to use for the LLM or a path to a file containing the system prompt")
|
|
38
|
+
|
|
39
|
+
def __init__(self, /, **data: Any) -> None:
|
|
40
|
+
prompt_or_path= data['system_prompt']
|
|
41
|
+
if os.path.exists(prompt_or_path):
|
|
42
|
+
with open(prompt_or_path, "r", encoding="utf-8") as f:
|
|
43
|
+
data['system_prompt'] = f.read()
|
|
44
|
+
|
|
45
|
+
super().__init__(**data)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AgentConfig(BaseModel):
|
|
49
|
+
agent: AgentItem = Field(description="The agent configuration node")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_model(api_key: str, model: str, base_url: str, reasoning_effort: str) -> BaseChatModel:
|
|
54
|
+
return ChatOpenAI(
|
|
55
|
+
model=model,
|
|
56
|
+
base_url=base_url,
|
|
57
|
+
api_key=lambda: api_key,
|
|
58
|
+
reasoning_effort=reasoning_effort
|
|
59
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import boto3
|
|
2
|
+
from langchain_core.tools import StructuredTool
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DynamoDbRegistryLookup:
|
|
6
|
+
def __init__(self, agent_card_tabel: str):
|
|
7
|
+
dynamo = boto3.resource("dynamodb", region_name="eu-central-1")
|
|
8
|
+
self.table = dynamo.Table(agent_card_tabel)
|
|
9
|
+
|
|
10
|
+
def get_agent_cards(self) -> list[str]:
|
|
11
|
+
|
|
12
|
+
items = self.table.scan().get("Items", [])
|
|
13
|
+
cards: list[str] = [it["card"] for it in items]
|
|
14
|
+
return cards
|
|
15
|
+
|
|
16
|
+
def as_tool(self) -> StructuredTool:
|
|
17
|
+
return StructuredTool.from_function(func=lambda: self.get_agent_cards(), name="agent_card_lookup",
|
|
18
|
+
description="Gets all available agent cards")
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import time
|
|
3
|
+
from contextlib import asynccontextmanager
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import boto3
|
|
7
|
+
from a2a.server.apps import A2ARESTFastAPIApplication
|
|
8
|
+
from a2a.server.request_handlers import DefaultRequestHandler
|
|
9
|
+
from a2a.server.tasks import InMemoryTaskStore
|
|
10
|
+
from a2a.types import AgentSkill, \
|
|
11
|
+
AgentCapabilities, AgentCard
|
|
12
|
+
from fastapi import FastAPI
|
|
13
|
+
|
|
14
|
+
from .executors import RoutingAgentExecutor
|
|
15
|
+
from .model import AgentConfig
|
|
16
|
+
from .registry import DynamoDbRegistryLookup
|
|
17
|
+
|
|
18
|
+
CAPABILITIES = AgentCapabilities(streaming=False, push_notifications=False)
|
|
19
|
+
|
|
20
|
+
HEART_BEAT_INTERVAL_SEC = 5
|
|
21
|
+
MAX_HEART_BEAT_MISSES = 3
|
|
22
|
+
|
|
23
|
+
AGENT_CARD_TABLE = "agent-cards"
|
|
24
|
+
|
|
25
|
+
def get_expire_at() -> int:
|
|
26
|
+
return int(time.time() + MAX_HEART_BEAT_MISSES * HEART_BEAT_INTERVAL_SEC)
|
|
27
|
+
|
|
28
|
+
async def heart_beat(name: str, agent_card_table: str, agent_card: AgentCard):
|
|
29
|
+
table = boto3.resource("dynamodb", region_name="eu-central-1").Table(agent_card_table)
|
|
30
|
+
table.put_item(Item={"id": name, "card": agent_card.model_dump_json(), "expireAt": get_expire_at()})
|
|
31
|
+
while True:
|
|
32
|
+
await asyncio.sleep(HEART_BEAT_INTERVAL_SEC)
|
|
33
|
+
table.update_item(
|
|
34
|
+
Key={"id": name},
|
|
35
|
+
UpdateExpression="SET expireAt = :expire_at",
|
|
36
|
+
ExpressionAttributeValues={":expire_at": get_expire_at()}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def load_app(agent_config: dict[str, Any]) -> FastAPI:
|
|
43
|
+
|
|
44
|
+
agent_config= AgentConfig.model_validate(agent_config)
|
|
45
|
+
|
|
46
|
+
skills = [AgentSkill(
|
|
47
|
+
id=skill.id,
|
|
48
|
+
name=skill.name,
|
|
49
|
+
description=skill.description,
|
|
50
|
+
tags=skill.tags)
|
|
51
|
+
for skill in agent_config.agent.card.skills]
|
|
52
|
+
skills.append(AgentSkill(
|
|
53
|
+
id='routing',
|
|
54
|
+
name='Agent routing',
|
|
55
|
+
description='Identifies the most suitable agent for the given task and returns the agent card',
|
|
56
|
+
tags=['agent', 'routing']
|
|
57
|
+
))
|
|
58
|
+
|
|
59
|
+
agent_card = AgentCard(
|
|
60
|
+
name=agent_config.agent.card.name,
|
|
61
|
+
description=agent_config.agent.card.description,
|
|
62
|
+
url=agent_config.agent.card.url,
|
|
63
|
+
version=agent_config.agent.card.version,
|
|
64
|
+
default_input_modes=agent_config.agent.card.default_input_modes,
|
|
65
|
+
default_output_modes=agent_config.agent.card.default_output_modes,
|
|
66
|
+
skills=skills,
|
|
67
|
+
preferred_transport=agent_config.agent.card.preferred_transport_protocol,
|
|
68
|
+
capabilities=CAPABILITIES
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
executor = RoutingAgentExecutor(agent_config=agent_config,
|
|
73
|
+
routing_tool=DynamoDbRegistryLookup(agent_card_tabel=AGENT_CARD_TABLE).as_tool())
|
|
74
|
+
|
|
75
|
+
@asynccontextmanager
|
|
76
|
+
async def lifespan(_: FastAPI):
|
|
77
|
+
asyncio.create_task(heart_beat(name=agent_card.name, agent_card_table=AGENT_CARD_TABLE, agent_card=agent_card))
|
|
78
|
+
yield
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
return A2ARESTFastAPIApplication(
|
|
82
|
+
agent_card=agent_card,
|
|
83
|
+
http_handler=DefaultRequestHandler(
|
|
84
|
+
agent_executor=executor,
|
|
85
|
+
task_store=InMemoryTaskStore() #TODO replace with dynamodb store
|
|
86
|
+
|
|
87
|
+
)).build(title=agent_card.name, lifespan=lifespan, root_path=f"/{agent_config.agent.card.name}") #TODO use extra parameter
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: distributed_a2a
|
|
3
|
+
Version: 0.1.5rc17
|
|
4
|
+
Summary: A library for building A2A agents with routing capabilities
|
|
5
|
+
Home-page: https://github.com/Barra-Technologies/distributed-a2a
|
|
6
|
+
Author: Fabian Bell
|
|
7
|
+
Author-email: Fabian Bell <fabian.bell@barrabytes.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/Barra-Technologies/distributed-a2a
|
|
10
|
+
Project-URL: Repository, https://github.com/Barra-Technologies/distributed-a2a
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: langchain>=0.1.0
|
|
23
|
+
Requires-Dist: langchain-core>=0.1.0
|
|
24
|
+
Requires-Dist: langchain-openai>=0.0.5
|
|
25
|
+
Requires-Dist: langgraph>=0.0.20
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Requires-Dist: boto3>=1.28.0
|
|
28
|
+
Requires-Dist: a2a>=0.1.0
|
|
29
|
+
Requires-Dist: build>=1.4.0
|
|
30
|
+
Requires-Dist: twine>=6.2.0
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: requires-python
|
|
35
|
+
|
|
36
|
+
# A2A Agent Library
|
|
37
|
+
|
|
38
|
+
A Python library for building A2A (Agent-to-Agent) agents with routing capabilities, DynamoDB-backed registry, and LangChain integration.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- **StatusAgent**: Base agent implementation with status tracking and structured responses
|
|
43
|
+
- **RoutingAgentExecutor**: Agent executor with intelligent routing capabilities
|
|
44
|
+
- **DynamoDB Registry**: Dynamic agent card registry with heartbeat mechanism
|
|
45
|
+
- **Server Utilities**: FastAPI application builder with A2A protocol support
|
|
46
|
+
- **LangChain Integration**: Built on LangChain for flexible model integration
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install distributed-a2a
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
1. Start a server with your agent application:
|
|
57
|
+
```python
|
|
58
|
+
from distributed_a2a import load_app
|
|
59
|
+
from a2a.types import AgentSkill
|
|
60
|
+
|
|
61
|
+
# Define your agent's skills
|
|
62
|
+
skills = [
|
|
63
|
+
AgentSkill(
|
|
64
|
+
id='example_skill',
|
|
65
|
+
name='Example Skill',
|
|
66
|
+
description='An example skill',
|
|
67
|
+
tags=['example']
|
|
68
|
+
)
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
# Create your agent application
|
|
72
|
+
app = load_app(
|
|
73
|
+
name="MyAgent",
|
|
74
|
+
description="My specialized agent",
|
|
75
|
+
skills=skills,
|
|
76
|
+
api_key="your-api-key",
|
|
77
|
+
system_prompt="You are a helpful assistant...",
|
|
78
|
+
host="http://localhost:8000"
|
|
79
|
+
)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
2. Send a request with the client
|
|
83
|
+
```python
|
|
84
|
+
from uuid import uuid4
|
|
85
|
+
|
|
86
|
+
from distributed_a2a import RoutingA2AClient
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
import asyncio
|
|
90
|
+
|
|
91
|
+
request = "Tell me the weather in Bonn"
|
|
92
|
+
client = RoutingA2AClient("http://localhost:8000")
|
|
93
|
+
response: str = asyncio.run(client.send_message(request, str(uuid4())))
|
|
94
|
+
print(response)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Requirements
|
|
98
|
+
|
|
99
|
+
- Python 3.10+
|
|
100
|
+
- langchain
|
|
101
|
+
- langchain-core
|
|
102
|
+
- langchain-openai
|
|
103
|
+
- langgraph
|
|
104
|
+
- pydantic
|
|
105
|
+
- boto3
|
|
106
|
+
- a2a
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
111
|
+
|
|
112
|
+
## Contributing
|
|
113
|
+
|
|
114
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
distributed_a2a/__init__.py,sha256=1q_7gRfBCGe-7sF_9YKzevyS97XQhtuFnZiYHIqaU-0,120
|
|
2
|
+
distributed_a2a/agent.py,sha256=CpIeEASjkIflGCiVo4f5c5_xUg3VwMr27l-o4cj73Mw,2597
|
|
3
|
+
distributed_a2a/client.py,sha256=2974Uw8YUuyBytwxxJJKYsWXCpEaIbGmMUHDraITxJ0,4149
|
|
4
|
+
distributed_a2a/executors.py,sha256=TNHO3eEIlKWObqBblcx_XiP5KahcfaGK1YuajWmQ5rE,4187
|
|
5
|
+
distributed_a2a/model.py,sha256=pvuoVg8QChYq21us49wZa7Pv-BlIU-mlfN2auVQvqdY,2676
|
|
6
|
+
distributed_a2a/registry.py,sha256=197eZVR6TW0isOUE0VjWSWs7aCqbWqnBzcV8EVXAxrI,677
|
|
7
|
+
distributed_a2a/server.py,sha256=eVccqBos4nMQqe9feyglGlMmUYIGz2t5jmBbMVt-NGE,3085
|
|
8
|
+
distributed_a2a-0.1.5rc17.dist-info/licenses/LICENSE,sha256=Btzdu2kIoMbdSp6OyCLupB1aRgpTCJ_szMimgEnpkkE,1056
|
|
9
|
+
distributed_a2a-0.1.5rc17.dist-info/METADATA,sha256=DMa6qn4InHdNC5TSVGG8P4Q95FlVcIJvl3MZ4svvBQQ,3107
|
|
10
|
+
distributed_a2a-0.1.5rc17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
distributed_a2a-0.1.5rc17.dist-info/top_level.txt,sha256=23qJ8n5k7796BHDK7a58uuO-X4GV0EgUWcGi8NIn-0k,16
|
|
12
|
+
distributed_a2a-0.1.5rc17.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
distributed_a2a
|