Skip to content

Commit 04756b8

Browse files
AbirAbbasclaude
andauthored
fix(sdk-python): use AsyncConfig.from_environment() for client default async config (#714)
AgentFieldClient constructed its default async_config with AsyncConfig(), ignoring AGENTFIELD_ASYNC_* environment overrides that Agent already honors. Initialize the default from AsyncConfig.from_environment() so client-level async behavior can be tuned via env vars, while preserving any explicitly passed async_config unchanged. Adds regression coverage for both paths. Fixes #621. Supersedes #632 (original change by liuzemei / neooosky); re-authored here so it can land without the outstanding CLA signature. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1a192cf commit 04756b8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

sdk/python/agentfield/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def __init__(
160160
self._did_authenticator = DIDAuthenticator(did=did, private_key_jwk=private_key_jwk)
161161

162162
# Async execution components
163-
self.async_config = async_config or AsyncConfig()
163+
self.async_config = async_config or AsyncConfig.from_environment()
164164
self._async_execution_manager: Optional[AsyncExecutionManager] = None
165165
self._async_http_client: Optional["httpx.AsyncClient"] = None
166166
self._async_http_client_lock: Optional[asyncio.Lock] = None

sdk/python/tests/test_async_config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from agentfield.async_config import AsyncConfig
2+
from agentfield.client import AgentFieldClient
23

34

45
def test_async_config_validate_defaults_ok():
@@ -48,3 +49,24 @@ def test_from_environment_overrides(monkeypatch):
4849
assert cfg.enable_event_stream is True
4950
assert cfg.event_stream_path == "/stream"
5051
assert cfg.event_stream_retry_backoff == 4.5
52+
53+
54+
def test_client_default_async_config_uses_environment(monkeypatch):
55+
monkeypatch.setenv("AGENTFIELD_ASYNC_MAX_EXECUTION_TIMEOUT", "321")
56+
monkeypatch.setenv("AGENTFIELD_ASYNC_ENABLE_EVENT_STREAM", "true")
57+
monkeypatch.setenv("AGENTFIELD_ASYNC_EVENT_STREAM_PATH", "/client-events")
58+
59+
client = AgentFieldClient()
60+
61+
assert client.async_config.max_execution_timeout == 321
62+
assert client.async_config.enable_event_stream is True
63+
assert client.async_config.event_stream_path == "/client-events"
64+
65+
66+
def test_client_keeps_explicit_async_config(monkeypatch):
67+
monkeypatch.setenv("AGENTFIELD_ASYNC_MAX_EXECUTION_TIMEOUT", "321")
68+
explicit_config = AsyncConfig(max_execution_timeout=456)
69+
70+
client = AgentFieldClient(async_config=explicit_config)
71+
72+
assert client.async_config is explicit_config

0 commit comments

Comments
 (0)