Skip to content

Commit 4a4d21e

Browse files
committed
Support AWF proxy endpoints via AWF_COPILOT_PROXY env var
When running inside an AWF sandbox, the API endpoint is a local proxy URL (e.g., http://172.30.0.30:10002) that the provider registry doesn't recognize. The AWF_COPILOT_PROXY env var names the upstream provider (e.g., 'api.githubcopilot.com') whose behaviour (headers, model defaults, catalog parsing) should be used with the proxy URL as base_url. This lets the taskflow agent work seamlessly through AWF's credential-isolating API proxy sidecar.
1 parent f139ac8 commit 4a4d21e

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/seclab_taskflow_agent/capi.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,34 @@ def check_tool_calls(self, _model: str, model_info: dict) -> bool:
140140
}
141141

142142
def get_provider(endpoint: str | None = None) -> APIProvider:
143-
"""Return the ``APIProvider`` for the given (or configured) endpoint URL."""
143+
"""Return the ``APIProvider`` for the given (or configured) endpoint URL.
144+
145+
When running inside an AWF (Agentic Workflow Firewall) sandbox, the
146+
``AWF_COPILOT_PROXY`` env var names the upstream provider whose behaviour
147+
(headers, model defaults, catalog format) the local proxy mirrors.
148+
The proxy URL is used as ``base_url`` while all other provider traits
149+
come from the named upstream.
150+
"""
144151
url = endpoint or get_AI_endpoint()
145152
netloc = urlparse(url).netloc
146153
provider = _PROVIDERS.get(netloc)
147154
if provider is not None:
148155
return provider
156+
157+
# AWF proxy support: AWF_COPILOT_PROXY names the upstream provider
158+
# (e.g. "api.githubcopilot.com") whose behaviour this proxy mirrors.
159+
awf_upstream = os.getenv("AWF_COPILOT_PROXY")
160+
if awf_upstream:
161+
upstream = _PROVIDERS.get(awf_upstream)
162+
if upstream:
163+
return type(upstream)(
164+
name=upstream.name,
165+
base_url=url,
166+
models_catalog=upstream.models_catalog,
167+
default_model=upstream.default_model,
168+
extra_headers=dict(upstream.extra_headers),
169+
)
170+
149171
# Unknown endpoint — return a generic provider with the given base URL
150172
return APIProvider(name="custom", base_url=url, default_model="please-set-default-model-via-env")
151173

0 commit comments

Comments
 (0)