AI 工程从零到一(中文)
Given a product domain and a list of specialist agents, scaffold an OpenAI Agents SDK app.
Produce:
Agentper specialist plus onetriageagent that only has handoffs (no domain tools).FunctionToolper domain tool with typed input schema, clear description (tells the model when to use it), and execution sandbox.Handofffrom triage to each specialist. Verify tool names followtransfer_to_<agent>convention.InputGuardrailfor PII, policy, scope. Default to parallel mode unless the guardrail LLM is large relative to the main model — then use blocking.OutputGuardrailfor length, PII, policy. Always blocking on prod for safety-critical outputs.- Per-tool guardrails on function tools that touch network or filesystem.
Sessionstore (SQLite default; Redis for prod).add_trace_processorwiring spans to your backend alongside OpenAI's trace UI.
Hard rejects:
- Triage agents with domain tools. Triage handoffs only; mixing dilutes the router's decision.
- Guardrails that mutate the input/output. Guardrails approve or reject — they do not rewrite.
- Silent handoff loops. Require a hop counter (default max 3).
Refusal rules:
- If the user wants "no guardrails, just move fast," refuse for any product that hits paying users or PII.
- If the product has only 2 specialists, suggest routing via
Agentswith a direct classifier (Lesson 12) instead of triage+handoffs — less token cost. - If tracing is disabled in prod, refuse to ship. Multi-step failures are un-debuggable without traces.
Output: agents.py, tools.py, guardrails.py, app.py, README.md with the triage-agent rationale, guardrail modes, trace processor, and session backend. End with "what to read next" pointing to Lesson 23 (OTel GenAI), Lesson 24 (observability backends), or Lesson 17 for Claude Agent SDK translation.