@@ -80,6 +80,7 @@ def __init__(
8080 client : Client | None = None ,
8181 http_client : httpx .AsyncClient | None = None ,
8282 auth_interceptor : AuthInterceptor | None = None ,
83+ timeout : float | httpx .Timeout | None = None ,
8384 ** kwargs : Any ,
8485 ) -> None :
8586 """Initialize the A2AAgent.
@@ -93,10 +94,14 @@ def __init__(
9394 client: The A2A client for the agent.
9495 http_client: Optional httpx.AsyncClient to use.
9596 auth_interceptor: Optional authentication interceptor for secured endpoints.
97+ timeout: Request timeout configuration. Can be a float (applied to all timeout components),
98+ httpx.Timeout object (for full control), or None (uses 10.0s connect, 60.0s read,
99+ 10.0s write, 5.0s pool - optimized for A2A operations).
96100 kwargs: any additional properties, passed to BaseAgent.
97101 """
98102 super ().__init__ (id = id , name = name , description = description , ** kwargs )
99103 self ._http_client : httpx .AsyncClient | None = http_client
104+ self ._timeout_config = self ._create_timeout_config (timeout )
100105 if client is not None :
101106 self .client = client
102107 self ._close_http_client = True
@@ -109,14 +114,8 @@ def __init__(
109114
110115 # Create or use provided httpx client
111116 if http_client is None :
112- timeout = httpx .Timeout (
113- connect = 10.0 , # 10 seconds to establish connection
114- read = 60.0 , # 60 seconds to read response (A2A operations can take time)
115- write = 10.0 , # 10 seconds to send request
116- pool = 5.0 , # 5 seconds to get connection from pool
117- )
118117 headers = prepend_agent_framework_to_user_agent ()
119- http_client = httpx .AsyncClient (timeout = timeout , headers = headers )
118+ http_client = httpx .AsyncClient (timeout = self . _timeout_config , headers = headers )
120119 self ._http_client = http_client # Store for cleanup
121120 self ._close_http_client = True
122121
@@ -143,6 +142,32 @@ def __init__(
143142 f"Fallback error: { fallback_error } "
144143 ) from transport_error
145144
145+ def _create_timeout_config (self , timeout : float | httpx .Timeout | None ) -> httpx .Timeout :
146+ """Create httpx.Timeout configuration from user input.
147+
148+ Args:
149+ timeout: User-provided timeout configuration
150+
151+ Returns:
152+ Configured httpx.Timeout object
153+ """
154+ if timeout is None :
155+ # Default timeout configuration (preserving original values)
156+ return httpx .Timeout (
157+ connect = 10.0 , # 10 seconds to establish connection
158+ read = 60.0 , # 60 seconds to read response (A2A operations can take time)
159+ write = 10.0 , # 10 seconds to send request
160+ pool = 5.0 , # 5 seconds to get connection from pool
161+ )
162+ if isinstance (timeout , float ):
163+ # Simple timeout
164+ return httpx .Timeout (timeout )
165+ if isinstance (timeout , httpx .Timeout ):
166+ # Full timeout configuration provided by user
167+ return timeout
168+ msg = f"Invalid timeout type: { type (timeout )} . Expected float, httpx.Timeout, or None."
169+ raise TypeError (msg )
170+
146171 async def __aenter__ (self ) -> "A2AAgent" :
147172 """Async context manager entry."""
148173 return self
0 commit comments