Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 0 additions & 16 deletions src/a2a/client/base_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from collections.abc import AsyncGenerator, AsyncIterator, Callable
from types import TracebackType
from typing import Any

from typing_extensions import Self

from a2a.client.client import (
Client,
ClientCallContext,
Expand Down Expand Up @@ -48,19 +45,6 @@ def __init__(
self._config = config
self._transport = transport

async def __aenter__(self) -> Self:
"""Enters the async context manager, returning the client itself."""
return self

async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Exits the async context manager, ensuring close() is called."""
await self.close()

async def send_message(
self,
request: Message,
Expand Down
20 changes: 20 additions & 0 deletions src/a2a/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

from abc import ABC, abstractmethod
from collections.abc import AsyncIterator, Callable, Coroutine
from types import TracebackType
from typing import Any

import httpx

from typing_extensions import Self

from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
from a2a.client.optionals import Channel
from a2a.types.a2a_pb2 import (
Expand Down Expand Up @@ -106,6 +109,19 @@ def __init__(
self._consumers = consumers
self._middleware = middleware

async def __aenter__(self) -> Self:
"""Enters the async context manager."""
return self

async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Exits the async context manager and closes the client."""
await self.close()

@abstractmethod
async def send_message(
self,
Expand Down Expand Up @@ -217,3 +233,7 @@ async def consume(
return
for c in self._consumers:
await c(event, card)

@abstractmethod
async def close(self) -> None:
"""Closes the client and releases any underlying resources."""
Loading