Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
298a443
feat: Add Agent Framework to A2A bridge support
Shubham-Kumar-2000 Nov 23, 2025
828b733
fix: Update references from agent_thread_storage to _agent_thread_sto…
Shubham-Kumar-2000 Nov 23, 2025
255ee71
Refactor A2A agent framework and improve code structure
Shubham-Kumar-2000 Nov 23, 2025
1e600dc
fix: Lint fix new line added
Shubham-Kumar-2000 Nov 23, 2025
c7a8b80
test: Add unit tests for AgentThreadStorage and InMemoryAgentThreadSt…
Shubham-Kumar-2000 Nov 23, 2025
db5bdf3
refactor: Update type hints to use new syntax for Union and List
Shubham-Kumar-2000 Nov 23, 2025
a3a5c48
fix: Validate RequestContext for context_id and message before execution
Shubham-Kumar-2000 Nov 23, 2025
4c43248
Refactor tests and remove A2aExecutionContext references
Shubham-Kumar-2000 Nov 23, 2025
cc2df5c
Refactor A2AExecutor tests and remove event adapter
Shubham-Kumar-2000 Nov 25, 2025
c732a05
refactor: Remove AgentThreadStorage and InMemoryAgentThreadStorage cl…
Shubham-Kumar-2000 Nov 30, 2025
64c1cfb
feat: A2AExecutor to have its own override able save and get threads …
Shubham-Kumar-2000 Nov 30, 2025
1f8a002
fix: linter bugs
Shubham-Kumar-2000 Nov 30, 2025
293f25d
Merge branch 'main' of https://github.com/Shubham-Kumar-2000/agent-fr…
Shubham-Kumar-2000 Nov 30, 2025
e3bb889
removed unnecessary changes form core package
Shubham-Kumar-2000 Nov 30, 2025
960bb22
new line added
Shubham-Kumar-2000 Nov 30, 2025
ed01679
Merge branch 'main' of https://github.com/microsoft/agent-framework i…
Shubham-Kumar-2000 Feb 26, 2026
f8ee82b
Refactor A2AExecutor tests and update imports
Shubham-Kumar-2000 Feb 27, 2026
f14e7c4
Update A2A documentation: enhance usage examples for A2AAgent and A2A…
Shubham-Kumar-2000 Feb 27, 2026
9d84791
Updated uv lock
Shubham-Kumar-2000 Feb 27, 2026
6e61d13
Fix metadata assertion in TestA2AExecutorHandleEvents and reorder loa…
Shubham-Kumar-2000 Feb 27, 2026
14b17d8
Update agent card configuration: add default input and output modes, …
Shubham-Kumar-2000 Feb 27, 2026
ae34dcf
Fix assertion for metadata in TestA2AExecutorHandleEvents
Shubham-Kumar-2000 Feb 27, 2026
4674494
Fix formatting issues in TestA2AExecutorExecute and TestA2AExecutorIn…
Shubham-Kumar-2000 Feb 27, 2026
7022f7f
Enhance A2AExecutor documentation with examples and clarify agent exe…
Shubham-Kumar-2000 Feb 27, 2026
1c7a196
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Feb 27, 2026
25c5528
Merge branch 'main' of https://github.com/microsoft/agent-framework i…
Shubham-Kumar-2000 Mar 5, 2026
556f1d3
Merge branch 'agent_framework_to_a2a' of https://github.com/Shubham-K…
Shubham-Kumar-2000 Mar 5, 2026
8c9feba
Merge branch 'main' of https://github.com/microsoft/agent-framework i…
Shubham-Kumar-2000 Mar 12, 2026
568fbd5
Revert uv lock to main
Shubham-Kumar-2000 Mar 12, 2026
c2f09c3
Refactor A2AExecutor: Improve formatting and streamline constructor p…
Shubham-Kumar-2000 Mar 12, 2026
46c6dcf
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Mar 22, 2026
9791458
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 4, 2026
4d3cf2b
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 10, 2026
50f8e83
Apply suggestions from code review
Shubham-Kumar-2000 Apr 13, 2026
8e31511
Refactor A2AExecutor to use SupportsAgentRun and enhance logging; upd…
Shubham-Kumar-2000 Apr 13, 2026
0297c6f
Merge branch 'main' into agent_framework_to_a2a
eavanvalkenburg Apr 14, 2026
327352f
Enhance A2AExecutor with streaming support and custom run arguments; …
Shubham-Kumar-2000 Apr 15, 2026
e5b42a9
Merge branch 'agent_framework_to_a2a' of https://github.com/Shubham-K…
Shubham-Kumar-2000 Apr 15, 2026
e857572
Enhance A2AExecutor event handling with streamed artifact tracking; u…
Shubham-Kumar-2000 Apr 15, 2026
81032f8
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 15, 2026
59dea33
Refactor A2AExecutor to enforce type hints for stream and run_kwargs …
Shubham-Kumar-2000 Apr 16, 2026
c1340d3
Merge branch 'agent_framework_to_a2a' of https://github.com/Shubham-K…
Shubham-Kumar-2000 Apr 16, 2026
fad2e82
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 16, 2026
dae1c19
Refactor A2AExecutor and tests: replace AsyncMock with MagicMock for …
Shubham-Kumar-2000 Apr 16, 2026
877cefd
Merge branch 'agent_framework_to_a2a' of https://github.com/Shubham-K…
Shubham-Kumar-2000 Apr 16, 2026
2ce08eb
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 16, 2026
39b1491
refactor: streamline imports and improve code readability across mult…
Shubham-Kumar-2000 Apr 17, 2026
6a5f29d
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 17, 2026
9bb1fae
feat: enhance A2AExecutor cancel method with context validation and f…
Shubham-Kumar-2000 Apr 20, 2026
0257d01
feat: implement get_uri_data utility function for extracting base64 d…
Shubham-Kumar-2000 Apr 21, 2026
1e5766c
fix: update import path for get_uri_data utility function in A2AExecu…
Shubham-Kumar-2000 Apr 21, 2026
9889e68
fix: correct error message handling in A2AExecutor and update test as…
Shubham-Kumar-2000 Apr 21, 2026
0f46d52
Merge branch 'main' into agent_framework_to_a2a
Shubham-Kumar-2000 Apr 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/packages/a2a/agent_framework_a2a/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import importlib.metadata

from ._a2a_event_adapter import A2aEventAdapter, BaseA2aEventAdapter
from ._a2a_executor import A2aExecutor
from ._agent import A2AAgent

try:
Expand All @@ -11,5 +13,8 @@

__all__ = [
"A2AAgent",
"A2aEventAdapter",
"A2aExecutor",
"BaseA2aEventAdapter",
"__version__",
]
422 changes: 422 additions & 0 deletions python/packages/a2a/agent_framework_a2a/_a2a_event_adapter.py

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions python/packages/a2a/agent_framework_a2a/_a2a_executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright (c) Microsoft. All rights reserved.

from asyncio import CancelledError

from a2a.server.agent_execution import AgentExecutor, RequestContext
from a2a.server.events import EventQueue
from a2a.server.tasks import TaskUpdater
from a2a.types import Part, Task, TaskState, TextPart
from a2a.utils import new_task
from agent_framework import (
AgentThread,
AgentThreadStorage,
ChatAgent,
ChatMessage,
InMemoryAgentThreadStorage,
Role,
WorkflowAgent,
)

from ._a2a_event_adapter import A2aEventAdapter, BaseA2aEventAdapter


class A2aExecutor(AgentExecutor):
Comment thread
Shubham-Kumar-2000 marked this conversation as resolved.
Outdated
"""Execute AI agents using the A2A (Agent-to-Agent) protocol.

The A2aExecutor bridges AI agents built with the agent_framework library and the A2A protocol,
enabling structured agent execution with event-driven communication. It manages agent threads,
handles execution contexts, and converts agent responses into A2A protocol events.

The executor supports both ChatAgent and WorkflowAgent types, persists conversation threads
using configurable storage, and provides comprehensive error handling with task status updates.

Args:
agent_thread_storage (AgentThreadStorage): Storage backend for persisting agent conversation threads.
Defaults to InMemoryAgentThreadStorage if not provided.
agent (Union[ChatAgent, WorkflowAgent]): The AI agent to execute.
event_adapter (A2aEventAdapter): Adapter for converting agent responses to A2A protocol events.
Defaults to BaseA2aEventAdapter if not provided.

Example:
Basic usage with a ChatAgent:

>>> from agent_framework import ChatAgent
>>> from agent_framework.openai import OpenAIResponsesClient
>>> from a2a.server.events import EventQueue
>>> from a2a.server.agent_execution import RequestContext
>>>
>>> # Initialize the AI client and agent
>>> agent = OpenAIResponsesClient().create_agent(
... name="WeatherBot",
... instructions="You are a helpful weather assistant.",
... )
>>>
>>> # Create the executor with default event adapter and storage
>>> executor = A2aExecutor(agent=agent)
>>>
>>> # Execute an agent within an async context
>>> async def run_example():
... event_queue = EventQueue()
... request_context = RequestContext(user_input="What is the weather today?", context_id="user-123")
... await executor.execute(request_context, event_queue)
... # Events are queued in event_queue for processing

Custom event adapter and persistent storage:

>>> from agent_framework import InMemoryAgentThreadStorage
>>> from agent_framework.a2a import BaseA2aEventAdapter
>>>
>>> custom_adapter = BaseA2aEventAdapter()
>>> storage = InMemoryAgentThreadStorage()
>>>
>>> executor = A2aExecutor(agent=agent, event_adapter=custom_adapter, agent_thread_storage=storage)
>>>
>>> # The same context_id will reuse the same conversation thread
>>> async def run_multi_turn():
... event_queue = EventQueue()
... context_id = "conversation-session-1"
...
... # First turn
... request1 = RequestContext(user_input="Hello, who are you?", context_id=context_id)
... await executor.execute(request1, event_queue)
...
... # Second turn (same conversation thread)
... request2 = RequestContext(user_input="What did I just ask?", context_id=context_id)
... await executor.execute(request2, event_queue)
"""

def __init__(
self,
agent: ChatAgent | WorkflowAgent,
event_adapter: A2aEventAdapter | None = None,
agent_thread_storage: AgentThreadStorage | None = None,
):
"""Initialize the A2aExecutor.

Args:
agent: The AI agent to execute. Can be a ChatAgent for conversational tasks
or a WorkflowAgent for multistep agent workflows.
event_adapter: Optional adapter for converting agent responses to A2A protocol events.
If not provided, BaseA2aEventAdapter is used.
agent_thread_storage: Optional storage backend for persisting agent conversation threads.
If not provided, InMemoryAgentThreadStorage is used. For production systems,
consider using persistent storage to maintain conversation state across restarts.
"""
super().__init__()
self._agent_thread_storage: AgentThreadStorage = (
agent_thread_storage if agent_thread_storage else InMemoryAgentThreadStorage()
)
self._agent: ChatAgent | WorkflowAgent = agent
self._event_adapter: A2aEventAdapter = event_adapter if event_adapter else BaseA2aEventAdapter()

async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
Comment thread
Shubham-Kumar-2000 marked this conversation as resolved.
# Cancellation handled at A2A protocol level
pass

Comment thread
moonbox3 marked this conversation as resolved.
Outdated
async def get_agent_thread(self, task: Task) -> AgentThread:
"""Get or create the agent thread for the given context."""
thread = await self._agent_thread_storage.load_thread(task.context_id)
if not thread:
thread = self._agent.get_new_thread()
await self._agent_thread_storage.save_thread(task.context_id, thread)
return thread

async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
"""Execute the agent with the given context and event queue."""
if context.context_id is None:
raise ValueError("Context ID must be provided in the RequestContext")
if context.message is None:
raise ValueError("Message must be provided in the RequestContext")

query = context.get_user_input()
task = context.current_task

if not task:
task = new_task(context.message)
await event_queue.enqueue_event(task)

updater = TaskUpdater(event_queue, task.id, context.context_id)
await updater.submit()

agent_thread = await self.get_agent_thread(task)
agent = self._agent
try:
await updater.start_work()
# Create a ChatMessage from the query
user_message = ChatMessage(role=Role.USER, text=query)

# Run the agent with the message
response = await agent.run(user_message, thread=agent_thread)
response_messages = response.messages
if not isinstance(response_messages, list):
response_messages = [response_messages]
for message in response_messages:
await self._event_adapter.handle_events(message, updater)
# Mark as complete
await updater.complete()
except CancelledError:
await updater.update_status(state=TaskState.canceled, final=True)
except Exception as e:
await updater.update_status(
state=TaskState.failed,
final=True,
message=updater.new_agent_message([Part(root=TextPart(text=str(e.args)))]),
Comment thread
Shubham-Kumar-2000 marked this conversation as resolved.
Outdated
)
Loading