Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 2 additions & 0 deletions python/packages/a2a/agent_framework_a2a/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def __init__(

super().__init__(id=id, name=name, description=description, **kwargs)
self._http_client: httpx.AsyncClient | None = http_client
# By default, leave a caller-supplied HTTP client open; specific paths may override this below.
self._close_http_client = False
self._timeout_config = self._create_timeout_config(timeout)
bindings = supported_protocol_bindings if supported_protocol_bindings is not None else ["JSONRPC"]
if client is not None:
Expand Down
10 changes: 10 additions & 0 deletions python/packages/a2a/tests/test_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ async def test_context_manager_no_cleanup_when_no_http_client() -> None:
pass


async def test_context_manager_does_not_close_caller_supplied_http_client() -> None:
"""A caller-supplied http_client (without client=) must survive __aexit__. See issue #7950."""
mock_http_client = AsyncMock()

async with A2AAgent(url="http://localhost:9999/", http_client=cast(Any, mock_http_client)):
pass

mock_http_client.aclose.assert_not_called()


def test_prepare_message_for_a2a_with_multiple_contents() -> None:
"""Test conversion of Message with multiple contents."""

Expand Down
Loading