Skip to content

Commit b709d87

Browse files
danielmillerpclaude
andcommitted
fix(examples): address review — max_turns ceiling, LITELLM_API_KEY guard, temporal instructions
- Add max_turns=10 to all Runner.run calls (sync/async/temporal + template) so an agent with shell access can't loop unbounded. - LITELLM_API_KEY only sets OPENAI_API_KEY when one isn't already set (don't clobber a real key). - Temporal workflow: instructions no longer call .format(timestamp=...) (the placeholder was missing -> no-op, and datetime.now() is non-deterministic inside a Temporal workflow); use the static instructions and drop the unused import. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e928801 commit b709d87

7 files changed

Lines changed: 8 additions & 10 deletions

File tree

  • examples/tutorials
  • src/agentex/lib/cli/templates/sync-openai-agents-local-sandbox/project

examples/tutorials/00_sync/050_openai_agents_local_sandbox/project/acp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# LiteLLM proxy auth: copy LITELLM_API_KEY to OPENAI_API_KEY for OpenAI client
3636
# compatibility, so the same example works behind the Scale LiteLLM gateway.
3737
_litellm_key = os.environ.get("LITELLM_API_KEY")
38-
if _litellm_key:
38+
if _litellm_key and not os.environ.get("OPENAI_API_KEY"):
3939
os.environ["OPENAI_API_KEY"] = _litellm_key
4040

4141
SGP_API_KEY = os.environ.get("SGP_API_KEY", "")

examples/tutorials/00_sync/050_openai_agents_local_sandbox/project/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ async def run_agent(user_message: str) -> str:
8888
"""
8989
agent = create_agent()
9090
run_config = create_run_config()
91-
result = await Runner.run(agent, input=user_message, run_config=run_config)
91+
result = await Runner.run(agent, input=user_message, run_config=run_config, max_turns=10)
9292
return result.final_output

examples/tutorials/10_async/00_base/120_openai_agents_local_sandbox/project/acp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# LiteLLM proxy auth: copy LITELLM_API_KEY to OPENAI_API_KEY for OpenAI client
4242
# compatibility, so the same example works behind the Scale LiteLLM gateway.
4343
_litellm_key = os.environ.get("LITELLM_API_KEY")
44-
if _litellm_key:
44+
if _litellm_key and not os.environ.get("OPENAI_API_KEY"):
4545
os.environ["OPENAI_API_KEY"] = _litellm_key
4646

4747
add_tracing_processor_config(

examples/tutorials/10_async/00_base/120_openai_agents_local_sandbox/project/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ async def run_agent(input_list: list) -> "Runner":
9292
"""
9393
agent = create_agent()
9494
run_config = create_run_config()
95-
return await Runner.run(agent, input=input_list, run_config=run_config)
95+
return await Runner.run(agent, input=input_list, run_config=run_config, max_turns=10)

examples/tutorials/10_async/10_temporal/120_openai_agents_local_sandbox/project/workflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import os
3232
import json
33-
from datetime import datetime
3433

3534
from agents import Runner
3635
from temporalio import workflow
@@ -147,9 +146,7 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
147146
agent = SandboxAgent(
148147
name="Local Sandbox Assistant",
149148
model=MODEL_NAME,
150-
instructions=INSTRUCTIONS.format(
151-
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
152-
),
149+
instructions=INSTRUCTIONS,
153150
capabilities=[Shell()],
154151
)
155152

@@ -177,6 +174,7 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
177174
self._state.input_list,
178175
run_config=run_config,
179176
hooks=TemporalStreamingHooks(task_id=params.task.id),
177+
max_turns=10,
180178
)
181179

182180
# IMPORTANT: We do NOT post the assistant message ourselves here.

src/agentex/lib/cli/templates/sync-openai-agents-local-sandbox/project/acp.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ logger = make_logger(__name__)
3535
# LiteLLM proxy auth: copy LITELLM_API_KEY to OPENAI_API_KEY for OpenAI client
3636
# compatibility, so the same agent works behind the Scale LiteLLM gateway.
3737
_litellm_key = os.environ.get("LITELLM_API_KEY")
38-
if _litellm_key:
38+
if _litellm_key and not os.environ.get("OPENAI_API_KEY"):
3939
os.environ["OPENAI_API_KEY"] = _litellm_key
4040

4141
SGP_API_KEY = os.environ.get("SGP_API_KEY", "")

src/agentex/lib/cli/templates/sync-openai-agents-local-sandbox/project/agent.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ async def run_agent(user_message: str) -> str:
8787
"""
8888
agent = create_agent()
8989
run_config = create_run_config()
90-
result = await Runner.run(agent, input=user_message, run_config=run_config)
90+
result = await Runner.run(agent, input=user_message, run_config=run_config, max_turns=10)
9191
return result.final_output

0 commit comments

Comments
 (0)