From db31a62edd96230121d9b912b90fdd1bb22e64b6 Mon Sep 17 00:00:00 2001 From: Daniel Miller Date: Fri, 8 May 2026 14:57:53 -0400 Subject: [PATCH] fix: wire SGP_CLIENT_BASE_URL and silence openai-agents tracer in templates Two tracing pitfalls hit when running the openai-agents templates against a non-default SGP environment with a LiteLLM proxy key: 1. SGPTracingProcessorConfig hardcoded sgp_base_url=None so traces always went to the SDK default (api.egp.scale.com) regardless of SGP_CLIENT_BASE_URL. Wired the env var through for sync-openai-agents and temporal-openai-agents. sync-langgraph and default-langgraph already had this; no change there. 2. The openai-agents SDK's native tracer ships traces to api.openai.com using OPENAI_API_KEY. When OPENAI_API_KEY is a LiteLLM proxy key the SDK errors with 401 on every request. Calling set_tracing_disabled(True) at module load silences that exporter; SGP traces still flow through the Agentex tracing manager. Also added SGP_CLIENT_BASE_URL to every .env.example.j2 so users see the knob when they copy .env.example to .env. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../lib/cli/templates/default-langgraph/.env.example.j2 | 1 + src/agentex/lib/cli/templates/default/.env.example.j2 | 1 + .../lib/cli/templates/sync-langgraph/.env.example.j2 | 1 + .../lib/cli/templates/sync-openai-agents/.env.example.j2 | 1 + .../cli/templates/sync-openai-agents/project/acp.py.j2 | 9 ++++++++- src/agentex/lib/cli/templates/sync/.env.example.j2 | 1 + .../cli/templates/temporal-openai-agents/.env.example.j2 | 1 + .../temporal-openai-agents/project/workflow.py.j2 | 9 ++++++++- src/agentex/lib/cli/templates/temporal/.env.example.j2 | 1 + 9 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/agentex/lib/cli/templates/default-langgraph/.env.example.j2 b/src/agentex/lib/cli/templates/default-langgraph/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/default-langgraph/.env.example.j2 +++ b/src/agentex/lib/cli/templates/default-langgraph/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/default/.env.example.j2 b/src/agentex/lib/cli/templates/default/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/default/.env.example.j2 +++ b/src/agentex/lib/cli/templates/default/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/sync-langgraph/.env.example.j2 b/src/agentex/lib/cli/templates/sync-langgraph/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/sync-langgraph/.env.example.j2 +++ b/src/agentex/lib/cli/templates/sync-langgraph/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/sync-openai-agents/.env.example.j2 b/src/agentex/lib/cli/templates/sync-openai-agents/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/sync-openai-agents/.env.example.j2 +++ b/src/agentex/lib/cli/templates/sync-openai-agents/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/sync-openai-agents/project/acp.py.j2 b/src/agentex/lib/cli/templates/sync-openai-agents/project/acp.py.j2 index 2295eccb3..0b3b482fe 100644 --- a/src/agentex/lib/cli/templates/sync-openai-agents/project/acp.py.j2 +++ b/src/agentex/lib/cli/templates/sync-openai-agents/project/acp.py.j2 @@ -13,7 +13,12 @@ from agentex.types.task_message_update import TaskMessageUpdate, StreamTaskMessa from agentex.types.task_message_content import TaskMessageContent from agentex.types.text_content import TextContent from agentex.lib.utils.logging import make_logger -from agents import Agent, Runner, RunConfig, function_tool +from agents import Agent, Runner, RunConfig, function_tool, set_tracing_disabled + +# Disable the openai-agents SDK's native tracer so it doesn't ship traces to +# api.openai.com using OPENAI_API_KEY (which may be a LiteLLM proxy key). +# SGP tracing below still runs via the Agentex tracing manager. +set_tracing_disabled(True) logger = make_logger(__name__) @@ -25,12 +30,14 @@ if _litellm_key: SGP_API_KEY = os.environ.get("SGP_API_KEY", "") SGP_ACCOUNT_ID = os.environ.get("SGP_ACCOUNT_ID", "") +SGP_CLIENT_BASE_URL = os.environ.get("SGP_CLIENT_BASE_URL", "") if SGP_API_KEY and SGP_ACCOUNT_ID: add_tracing_processor_config( SGPTracingProcessorConfig( sgp_api_key=SGP_API_KEY, sgp_account_id=SGP_ACCOUNT_ID, + sgp_base_url=SGP_CLIENT_BASE_URL, ) ) diff --git a/src/agentex/lib/cli/templates/sync/.env.example.j2 b/src/agentex/lib/cli/templates/sync/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/sync/.env.example.j2 +++ b/src/agentex/lib/cli/templates/sync/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/temporal-openai-agents/.env.example.j2 b/src/agentex/lib/cli/templates/temporal-openai-agents/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/temporal-openai-agents/.env.example.j2 +++ b/src/agentex/lib/cli/templates/temporal-openai-agents/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL= diff --git a/src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 b/src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 index 94b5221fb..5b95d4479 100644 --- a/src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 +++ b/src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 @@ -10,7 +10,13 @@ from agentex.lib.core.temporal.types.workflow import SignalName from agentex.lib.utils.logging import make_logger from agentex.types.text_content import TextContent from agentex.lib.environment_variables import EnvironmentVariables -from agents import Agent, Runner +from agents import Agent, Runner, set_tracing_disabled + +# Disable the openai-agents SDK's native tracer so it doesn't ship traces to +# api.openai.com using OPENAI_API_KEY (which may be a LiteLLM proxy key). +# SGP tracing below still runs via the Agentex tracing manager. +set_tracing_disabled(True) + from agentex.lib.core.temporal.plugins.openai_agents.hooks.hooks import TemporalStreamingHooks from pydantic import BaseModel from typing import List, Dict, Any @@ -39,6 +45,7 @@ add_tracing_processor_config( SGPTracingProcessorConfig( sgp_api_key=os.environ.get("SGP_API_KEY", ""), sgp_account_id=os.environ.get("SGP_ACCOUNT_ID", ""), + sgp_base_url=os.environ.get("SGP_CLIENT_BASE_URL", ""), ) ) diff --git a/src/agentex/lib/cli/templates/temporal/.env.example.j2 b/src/agentex/lib/cli/templates/temporal/.env.example.j2 index 1e81b15dd..015f49ef7 100644 --- a/src/agentex/lib/cli/templates/temporal/.env.example.j2 +++ b/src/agentex/lib/cli/templates/temporal/.env.example.j2 @@ -10,3 +10,4 @@ LITELLM_API_KEY= # SGP Configuration (optional - for tracing) # SGP_API_KEY= # SGP_ACCOUNT_ID= +# SGP_CLIENT_BASE_URL=