microsoft / microsoft/agent-framework
Python: Add A2A metadata hooks for cross-agent runtime context
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
### Description
`A2AAgent` can send standard A2A message metadata, and `RequestContext` exposes inbound metadata on the server. However, there is currently no public way to bridge workflow runtime context into that metadata and then initialize the remote Microsoft Agent Framework session before execution.
This is needed when one workflow participant or tool produces structured runtime context and a later `A2AAgent` participant must send that context to a remote A2A server.
### Current behavior
- GroupChat correctly forwards `function_invocation_kwargs` to its participants.
- `A2AAgent.run()` accepts `function_invocation_kwargs` for interface compatibility but does not transmit them over A2A.
- `A2AAgent` already maps `Message.additional_properties["a2a_metadata"]` to A2A `Message.metadata`, but callers must construct this message metadata themselves.
- `A2AExecutor` receives the inbound `RequestContext`, including metadata, but creates the MAF session internally with no hook to initialize `session.state` before calling the agent.
### Desired behavior
Provide explicit, JSON-safe extension points for this flow without automatically serializing arbitrary runtime kwargs or placing application data in HTTP headers.
For example, one possible API would be:
```python
A2AAgent.run(
messages,
a2a_metadata={"context": runtime_context},
)
```
and a server-side hook such as:
```python
class A2AExecutor:
async def prepare_session(
self,
context: RequestContext,
session: AgentSession,
) -> None:
pass
```
The server implementation could then do:
```python
session.state["context"] = context.message.metadata.get("context")
```
### Minimal reproduction
```python
runtime_context = {"request_id": "example", "attributes": {"key": "value"}}
await workflow.run(
"Process the request.",
function_invocation_kwargs={"runtime_context": runtime_context},
)
```
The expected result is that the remote A2A server can retrieve the structured runtime context before invoking the MAF agent.
### Proposed scope
- Add a documented outbound A2A metadata mechanism to `A2AAgent`.
- Add a documented pre-execution session initialization hook to `A2AExecutor`.
- Add focused client and server tests proving metadata is available before remote agent execution.
- Document that only JSON-compatible, explicitly selected application data should be transmitted.
I am happy to contribute the implementation after the API direction is confirmed.
Contributor guide
Assessment
This issue has not been assessed yet.