๊ฐ€์ž… ํ›„ ์ดˆ๋Œ€ ๋งํฌ๋ฅผ ๊ณต์œ ํ•˜๋ฉด ๋™์˜์ƒ ์žฌ์ƒ ๋ฐ ์ดˆ๋Œ€ ๋ณด์ƒ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
๊ฐ€์ž… May 2026
280 ํŒ”๋กœ์ž‰ ์ค‘    415 ํŒฌ
# Practical and Useful Patterns for OpenAI Agent SDK ๐ŸŒ When handing off between agents, wouldn't it be great to pass structured reasons and metadata along? Handoff inputs and on_handoff let you transfer context-rich data for seamless agent transitions. ๐Ÿ“Œ Title: Handoffs โ€“ Handoff inputs ๐Ÿ”— URL: ๐Ÿงฉ Overview Handoff inputs allow the model to generate structured data (via a Pydantic model) that gets passed to the target agent during a handoff. Combined with the `on_handoff` callback, you can log escalation reasons, prefetch data the target agent needs, and inject additional context โ€” all before the target agent starts processing. ๐Ÿ›  Usage Define a Pydantic model `EscalationData(BaseModel)` with `reason: str`, `priority: str = "normal"`, and `customer_tier: str = "standard"` as structured handoff data. The `on_escalation(ctx: RunContext, input_data: EscalationData)` callback logs `input_data.reason` and `input_data.priority`, prefetches customer data using `ctx.context["customer_id"]`, and stores it in `ctx.context["customer_data"]`. Define `Agent(name="escalation", instructions="...")` as the escalation target and `Agent(name="triage", handoffs=[Handoff(agent=escalation_agent, input_type=EscalationData, on_handoff=on_escalation, handoff_description="Complex inquiries or urgent cases requiring escalation")])` as the triage agent. Execute with `await input="I was double-charged. I need this resolved immediately.", context={"customer_id": "C-12345"})`. ๐Ÿ— Practical Patterns **Structured Escalation Reasons** Define handoff reasons as typed Pydantic models like `EscalationData(reason, priority)`. Instead of free-text reasoning buried in conversation history, you get structured data that's easy to log, analyze, and act on programmatically. **Data Prefetching in on_handoff** Use the `on_handoff` callback to fetch data from databases or APIs that the target agent will need. This eliminates an extra tool-call round-trip after handoff, reducing latency. The target agent starts with all the context it needs. **Metadata Transfer** Pass `{"reason": "duplicate_charge", "priority": "high"}` to a refund agent so it can make policy decisions based on structured metadata rather than inferring from conversation history. More accurate, more reliable. **Audit Logging** Record handoff reasons, timing, and priority in `on_handoff` for audit trails. This data powers SLA dashboards and escalation trend analysis in customer support operations. ๐Ÿ’ก Use Cases ๐Ÿ”„ Customer support escalation with structured reason and priority ๐Ÿ’ณ Refund processing handoffs with explicit cause (duplicate charge / defective item / cancellation) ๐Ÿ“Š Escalation analytics via on_handoff logging to dashboards โšก Reduced target agent latency through on_handoff data prefetching โš ๏ธ Caveats - Too many required fields in `input_type` makes it harder for the model to generate accurate data. Keep required fields minimal and use defaults for optional ones. - Exceptions in `on_handoff` will fail the entire handoff. Wrap external API calls in try-except with fallback logic. - `on_handoff` runs synchronously. Heavy processing increases handoff latency โ€” keep it lightweight. - Without `input_type`, the `on_handoff` callback does not receive an `input_data` argument. โœจ Use handoff inputs to pass structured context between agents and make your multi-agent transitions seamless! #OpenAIAgentSDK# #AIAgent#
๋” ๋ณด๊ธฐ