Skip to content

Python: [agent-framework-a2a] A2AAgent.run() ignores session parameter - context_id not propagated to A2A protocol #4663

@florian-ivadolabs

Description

@florian-ivadolabs

Description

A2AAgent.run() accepts a session: AgentSession | None parameter but never uses it. The _prepare_message_for_a2a method creates an A2AMessage without setting context_id, so the a2a-sdk client auto-generates a new random context_id for every call.

This means:

  • No session continuity - The server cannot correlate multiple calls belonging to the same conversation.
    • No multi-workflow isolation - When multiple orchestrations run concurrently against the same A2A agent server, the single shared AgentExecutor instance has no stable key to separate their conversation histories.

Expected Behavior

When an AgentSession is provided to A2AAgent.run(), the session's session_id should be mapped to the A2A protocol's Message.context_id field. This would:

  1. Allow the server-side executor to key conversation history by context_id.
  2. Enable concurrent multi-agent workflows to run against the same agent server without cross-contaminating conversation state.

Current Behavior

In _agent.py, line ~265:

normalized_messages = normalize_messages(messages)
a2a_message = self._prepare_message_for_a2a(normalized_messages[-1])
a2a_stream = self.client.send_message(a2a_message)

The session parameter is not referenced. The A2AMessage is created without context_id, so the SDK generates a random UUID per call.

Reproduction

  1. Create a GroupChat with multiple A2A agent participants.
  2. Run two workflows concurrently against the same agent servers.
  3. Observe that context_id is different on every A2A call (even within the same workflow), and the server-side executor has no way to isolate conversation histories.

Suggested Fix

In _prepare_message_for_a2a, propagate the session ID:

def _prepare_message_for_a2a(self, message: Message) -> A2AMessage:
    # ... existing logic ...
    return A2AMessage(
        role=A2ARole("user"),
        parts=parts,
        message_id=message.message_id or uuid.uuid4().hex,
        context_id=self._current_session_id,  # from session passed to run()
        metadata=metadata,
    )

Workaround

We currently subclass A2AAgent to override _prepare_message_for_a2a and inject a stable context_id (UUID assigned at construction time), and key the server-side executor history by context_id.

Environment

  • agent-framework-a2a==1.0.0b260304
  • a2a-sdk (latest)
  • Python 3.12

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Planned

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions