Skip to content

Commit 00e8012

Browse files
committed
fix(showcase): claude-sdk-python missing openai dep crashed agent on import
Root cause: src/agents/a2ui_dynamic.py imported `openai` at module top level, but openai was not in requirements.txt. The agent_server.py imports a2ui_dynamic at top level too, so on container startup the entire FastAPI module failed to load with ModuleNotFoundError. entrypoint.sh's startup gate ("Agent failed to start - exiting") then bailed before Next.js launched, taking the whole container down. Railway's restart loop made every /demos/<id> route unreachable, which is exactly the symptom the D2 e2e-readiness probe reports as red across all 9 features in this framework column. Two-part fix: - Add openai>=1.50.0 to requirements.txt so the dep is actually installed in the agent-builder stage. - Move the `import openai` to a lazy import inside _generate_a2ui (mirroring the same pattern in agents/agent.py:339), so a future requirements regression localizes the failure to the one declarative-gen-ui demo instead of nuking the whole backend on module load.
1 parent 360cfb9 commit 00e8012

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

showcase/integrations/claude-sdk-python/requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ python-dotenv>=1.0.1
66
# Used by the multimodal demo to flatten PDFs to text so the model can
77
# read them without depending on Claude's PDF beta.
88
pypdf>=4.0.0
9+
# Used by the declarative-gen-ui demo (a2ui_dynamic.py) for the secondary
10+
# LLM bound to the render_a2ui tool. Imported at module top of
11+
# agents/a2ui_dynamic.py — without it the entire agent_server module fails
12+
# to load on container startup, taking the FastAPI backend down. The
13+
# entrypoint then exits before Next.js launches, making every demo route
14+
# unreachable (D2 e2e-readiness goes red across the board). Lazy-importing
15+
# inside _generate_a2ui would localize the failure but `requirements.txt`
16+
# is the right place to declare the runtime dep.
17+
openai>=1.50.0

showcase/integrations/claude-sdk-python/src/agents/a2ui_dynamic.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from typing import Any
2525

2626
import anthropic
27-
import openai
2827
from ag_ui.core import (
2928
EventType,
3029
RunAgentInput,
@@ -83,6 +82,13 @@
8382

8483
def _generate_a2ui(context: str, conversation_messages: list[dict[str, Any]] | None = None) -> dict[str, Any]:
8584
"""Invoke a secondary LLM bound to render_a2ui and return an operations container."""
85+
# Lazy-import openai so a missing/uninstalled dep doesn't take the entire
86+
# agent_server module down at import time — that import-time failure
87+
# cascades through entrypoint.sh ("Agent failed to start — exiting")
88+
# and prevents Next.js from booting, making every demo route in this
89+
# integration unreachable. Mirrors the same lazy-import pattern in
90+
# agents/agent.py:339 for the shared `generate_a2ui` tool handler.
91+
import openai
8692
client = openai.OpenAI()
8793
llm_messages: list[dict[str, Any]] = [
8894
{"role": "system", "content": context or "Generate a useful dashboard UI."},

0 commit comments

Comments
 (0)