distributed-a2a 0.1.5rc14__tar.gz

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.
@@ -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,2 @@
1
+ include README.md
2
+ include LICENSE
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: distributed_a2a
3
+ Version: 0.1.5rc14
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,79 @@
1
+ # A2A Agent Library
2
+
3
+ A Python library for building A2A (Agent-to-Agent) agents with routing capabilities, DynamoDB-backed registry, and LangChain integration.
4
+
5
+ ## Features
6
+
7
+ - **StatusAgent**: Base agent implementation with status tracking and structured responses
8
+ - **RoutingAgentExecutor**: Agent executor with intelligent routing capabilities
9
+ - **DynamoDB Registry**: Dynamic agent card registry with heartbeat mechanism
10
+ - **Server Utilities**: FastAPI application builder with A2A protocol support
11
+ - **LangChain Integration**: Built on LangChain for flexible model integration
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install distributed-a2a
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ 1. Start a server with your agent application:
22
+ ```python
23
+ from distributed_a2a import load_app
24
+ from a2a.types import AgentSkill
25
+
26
+ # Define your agent's skills
27
+ skills = [
28
+ AgentSkill(
29
+ id='example_skill',
30
+ name='Example Skill',
31
+ description='An example skill',
32
+ tags=['example']
33
+ )
34
+ ]
35
+
36
+ # Create your agent application
37
+ app = load_app(
38
+ name="MyAgent",
39
+ description="My specialized agent",
40
+ skills=skills,
41
+ api_key="your-api-key",
42
+ system_prompt="You are a helpful assistant...",
43
+ host="http://localhost:8000"
44
+ )
45
+ ```
46
+
47
+ 2. Send a request with the client
48
+ ```python
49
+ from uuid import uuid4
50
+
51
+ from distributed_a2a import RoutingA2AClient
52
+
53
+ if __name__ == "__main__":
54
+ import asyncio
55
+
56
+ request = "Tell me the weather in Bonn"
57
+ client = RoutingA2AClient("http://localhost:8000")
58
+ response: str = asyncio.run(client.send_message(request, str(uuid4())))
59
+ print(response)
60
+ ```
61
+
62
+ ## Requirements
63
+
64
+ - Python 3.10+
65
+ - langchain
66
+ - langchain-core
67
+ - langchain-openai
68
+ - langgraph
69
+ - pydantic
70
+ - boto3
71
+ - a2a
72
+
73
+ ## License
74
+
75
+ MIT
76
+
77
+ ## Contributing
78
+
79
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,7 @@
1
+ from .client import RoutingA2AClient
2
+ from .server import load_app
3
+
4
+ __all__ = [
5
+ "load_app",
6
+ "RoutingA2AClient"
7
+ ]
@@ -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.get_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))
@@ -0,0 +1,60 @@
1
+ import os
2
+ from typing import List
3
+
4
+ from anyio.functools import lru_cache
5
+ from langchain_core.language_models import BaseChatModel
6
+ from langchain_openai import ChatOpenAI
7
+ from pydantic import BaseModel, Field
8
+
9
+
10
+ class SkillConfig(BaseModel):
11
+ id: str = Field(description="The id of the skill e.g. weather")
12
+ name: str = Field(description="The name of the skill e.g. weather")
13
+ description: str = Field(description="A short description of the skill")
14
+ tags: List[str] = Field(description="The tags associated with the skill")
15
+
16
+
17
+ class LLMConfig(BaseModel):
18
+ base_url: str = Field(description="The base url of the LLM provider")
19
+ model: str = Field(description="The model to use for the LLM e.g. gpt-3.5-turbo")
20
+ api_key_env: str = Field(description="The environment variable containing the api key for the LLM provider")
21
+ reasoning_effort: str = Field(description="The reasoning effort to use for the LLM e.g. high", default="high")
22
+
23
+
24
+ class CardConfig(BaseModel):
25
+ name: str = Field(description="The name of the agent" )
26
+ description: str = Field(description="A short description of the agent")
27
+ version: str = Field(description="The version of the agent")
28
+ default_input_modes: List[str] = Field(description="The default input modes supported by the agent", default=["text","text/plaintext"])
29
+ default_output_modes: List[str] = Field(description="The default output modes supported by the agent", default=["text","text/plaintext"])
30
+ preferred_transport_protocol: str = Field(description="The preferred transport protocol for the agent", default="HTTP+JSON")
31
+ url: str = Field(description="The url of the agent")
32
+ skills: List[SkillConfig] = Field(description="The skills supported by the agent", default=[])
33
+
34
+
35
+ class AgentItem(BaseModel):
36
+ card: CardConfig = Field(description="The agent card configuration node")
37
+ llm: LLMConfig = Field(description="The LLM configuration node")
38
+ system_prompt: str = Field(description="The system prompt to use for the LLM or a path to a file containing the system prompt")
39
+
40
+ @lru_cache
41
+ def get_system_prompt(self) -> str:
42
+ if os.path.exists(self._system_prompt):
43
+ with open(self._system_prompt, 'r', encoding='utf-8') as file:
44
+ return file.read()
45
+
46
+ return self._system_prompt
47
+
48
+
49
+ class AgentConfig(BaseModel):
50
+ agent: AgentItem = Field(description="The agent configuration node")
51
+
52
+
53
+
54
+ def get_model(api_key: str, model: str, base_url: str, reasoning_effort: str) -> BaseChatModel:
55
+ return ChatOpenAI(
56
+ model=model,
57
+ base_url=base_url,
58
+ api_key=lambda: api_key,
59
+ reasoning_effort=reasoning_effort
60
+ )
@@ -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.5rc14
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,18 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ requirements.txt
6
+ setup.py
7
+ distributed_a2a/__init__.py
8
+ distributed_a2a/agent.py
9
+ distributed_a2a/client.py
10
+ distributed_a2a/executors.py
11
+ distributed_a2a/model.py
12
+ distributed_a2a/registry.py
13
+ distributed_a2a/server.py
14
+ distributed_a2a.egg-info/PKG-INFO
15
+ distributed_a2a.egg-info/SOURCES.txt
16
+ distributed_a2a.egg-info/dependency_links.txt
17
+ distributed_a2a.egg-info/requires.txt
18
+ distributed_a2a.egg-info/top_level.txt
@@ -0,0 +1,9 @@
1
+ langchain>=0.1.0
2
+ langchain-core>=0.1.0
3
+ langchain-openai>=0.0.5
4
+ langgraph>=0.0.20
5
+ pydantic>=2.0.0
6
+ boto3>=1.28.0
7
+ a2a>=0.1.0
8
+ build>=1.4.0
9
+ twine>=6.2.0
@@ -0,0 +1 @@
1
+ distributed_a2a
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "distributed_a2a"
7
+ version = "0.1.5rc14"
8
+ description = "A library for building A2A agents with routing capabilities"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Fabian Bell", email = "fabian.bell@barrabytes.com"}
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Topic :: Software Development :: Libraries :: Python Modules",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ ]
25
+ dynamic = ["dependencies"]
26
+
27
+ [tool.setuptools.dynamic]
28
+ dependencies = {file = ["requirements.txt"]}
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/Barra-Technologies/distributed-a2a"
32
+ Repository = "https://github.com/Barra-Technologies/distributed-a2a"
@@ -0,0 +1,9 @@
1
+ langchain>=0.1.0
2
+ langchain-core>=0.1.0
3
+ langchain-openai>=0.0.5
4
+ langgraph>=0.0.20
5
+ pydantic>=2.0.0
6
+ boto3>=1.28.0
7
+ a2a>=0.1.0
8
+ build>=1.4.0
9
+ twine>=6.2.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ with open("requirements.txt", "r", encoding="utf-8") as fh:
7
+ requirements = [line.strip() for line in fh if line.strip() and not line.startswith("#")]
8
+
9
+ setup(
10
+ name="distributed_a2a",
11
+ version="0.1.4",
12
+ author="Fabian Bell",
13
+ author_email="fabian.bell@barrabytes.com",
14
+ description="A library for building A2A agents with routing capabilities",
15
+ long_description=long_description,
16
+ long_description_content_type="text/markdown",
17
+ url="https://github.com/Barra-Technologies/distributed-a2a",
18
+ packages=find_packages(),
19
+ classifiers=[
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ ],
29
+ python_requires=">=3.10",
30
+ install_requires=requirements,
31
+ )