[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EM4M5MTCN16QXA3RMQC2EE":3,"skill-same:01M6EM4M5MTCN16QXA3RMQC2EE":79},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6EM4M5MTCN16QXA3RMQC2EE","scaffolding-openai-agents",null,"Builds AI agents using OpenAI Agents SDK with async\u002Fawait patterns and multi-agent orchestration.\nUse when creating tutoring agents, building agent handoffs, implementing tool-calling agents, or orchestrating multiple specialists.\nCovers Agent class, Runner patterns, function tools, guardrails, and streaming responses.\nNOT when using raw OpenAI API without SDK or other agent frameworks like LangChain.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fasmayaseen\u002Fscaffolding-openai-agents\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"scaffolding openai agents","openai agents","openai","scaffolding","multi-agent","frameworks","patterns","runner","agent orchestration","async","langchain","agents sdk","tool","api","Tools","Guardrails","streaming","openai api","orchestration","ai agents","2026-11-10 10:12:30",false,"---\r\nname: scaffolding-openai-agents\r\ndescription: |\r\n  Builds AI agents using OpenAI Agents SDK with async\u002Fawait patterns and multi-agent orchestration.\r\n  Use when creating tutoring agents, building agent handoffs, implementing tool-calling agents, or orchestrating multiple specialists.\r\n  Covers Agent class, Runner patterns, function tools, guardrails, and streaming responses.\r\n  NOT when using raw OpenAI API without SDK or other agent frameworks like LangChain.\r\n---\r\n\r\n# Scaffolding OpenAI Agents\r\n\r\nBuild production AI agents using OpenAI Agents SDK with native async\u002Fawait patterns.\r\n\r\n## Quick Start\r\n\r\n```bash\r\n# Project setup\r\nmkdir my-agent && cd my-agent\r\npython -m venv .venv && source .venv\u002Fbin\u002Factivate\r\npip install openai-agents\r\n\r\n# Set API key\r\nexport OPENAI_API_KEY=sk-...\r\n```\r\n\r\n```python\r\n# main.py\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nagent = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"You help students learn Python. Explain concepts clearly with examples.\"\r\n)\r\n\r\nasync def main():\r\n    result = await Runner.run(agent, \"Explain list comprehensions\")\r\n    print(result.final_output)\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n## Agent Configuration\r\n\r\n### Basic Agent\r\n\r\n```python\r\nfrom agents import Agent\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"\"\"You are an expert Python tutor.\r\n    Explain concepts clearly with examples.\r\n    Ask clarifying questions when needed.\r\n    Provide practice exercises after explanations.\"\"\",\r\n    model=\"gpt-4o\"\r\n)\r\n```\r\n\r\n### With Model Settings\r\n\r\n```python\r\nfrom agents import Agent, ModelSettings\r\n\r\nagent = Agent(\r\n    name=\"Creative Writer\",\r\n    instructions=\"Write creative stories based on prompts.\",\r\n    model=\"gpt-4o\",\r\n    model_settings=ModelSettings(\r\n        temperature=0.9,\r\n        max_tokens=2000\r\n    )\r\n)\r\n```\r\n\r\n### With Structured Output\r\n\r\n```python\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent\r\n\r\nclass CodeReview(BaseModel):\r\n    issues: list[str]\r\n    suggestions: list[str]\r\n    score: int\r\n\r\nreviewer = Agent(\r\n    name=\"Code Reviewer\",\r\n    instructions=\"Review Python code for issues and improvements.\",\r\n    output_type=CodeReview  # Forces structured JSON output\r\n)\r\n```\r\n\r\n## Runner Patterns\r\n\r\n### Async Run (Primary)\r\n\r\n```python\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nasync def main():\r\n    agent = Agent(name=\"Helper\", instructions=\"Be helpful\")\r\n\r\n    # Single query\r\n    result = await Runner.run(agent, \"What is Python?\")\r\n    print(result.final_output)\r\n\r\n    # With conversation history\r\n    messages = [\r\n        {\"role\": \"user\", \"content\": \"My name is Alex\"},\r\n        {\"role\": \"assistant\", \"content\": \"Nice to meet you, Alex!\"},\r\n        {\"role\": \"user\", \"content\": \"What's my name?\"}\r\n    ]\r\n    result = await Runner.run(agent, messages)\r\n    print(result.final_output)  # \"Your name is Alex\"\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n### Sync Run (Simple Scripts)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\nagent = Agent(name=\"Helper\", instructions=\"Be helpful\")\r\nresult = Runner.run_sync(agent, \"Hello!\")\r\nprint(result.final_output)\r\n```\r\n\r\n### Streaming Run\r\n\r\n```python\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nasync def main():\r\n    agent = Agent(name=\"Storyteller\", instructions=\"Tell engaging stories\")\r\n\r\n    result = Runner.run_streamed(agent, \"Tell me a short story\")\r\n\r\n    async for event in result.stream_events():\r\n        if hasattr(event, 'delta'):\r\n            print(event.delta, end='', flush=True)\r\n\r\n    print()  # Newline at end\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n### Conversation Continuation\r\n\r\n```python\r\nasync def chat_session():\r\n    agent = Agent(name=\"Tutor\", instructions=\"You are a Python tutor\")\r\n\r\n    # First turn\r\n    result1 = await Runner.run(agent, \"Explain decorators\")\r\n    print(f\"Tutor: {result1.final_output}\")\r\n\r\n    # Continue conversation\r\n    messages = result1.to_input_list() + [\r\n        {\"role\": \"user\", \"content\": \"Show me an example\"}\r\n    ]\r\n    result2 = await Runner.run(agent, messages)\r\n    print(f\"Tutor: {result2.final_output}\")\r\n```\r\n\r\n## Function Tools\r\n\r\n### Basic Tool\r\n\r\n```python\r\nfrom agents import Agent, function_tool\r\n\r\n@function_tool\r\ndef get_current_time() -> str:\r\n    \"\"\"Get the current time.\"\"\"\r\n    from datetime import datetime\r\n    return datetime.now().strftime(\"%H:%M:%S\")\r\n\r\n@function_tool\r\ndef calculate(expression: str) -> float:\r\n    \"\"\"Calculate a mathematical expression.\r\n\r\n    Args:\r\n        expression: A valid Python math expression like \"2 + 2\" or \"10 * 5\"\r\n    \"\"\"\r\n    return eval(expression)  # Use safe_eval in production\r\n\r\nagent = Agent(\r\n    name=\"Assistant\",\r\n    instructions=\"Help with calculations and time queries.\",\r\n    tools=[get_current_time, calculate]\r\n)\r\n```\r\n\r\n### Async Tool\r\n\r\n```python\r\nimport httpx\r\nfrom agents import Agent, function_tool\r\n\r\n@function_tool\r\nasync def fetch_weather(city: str) -> str:\r\n    \"\"\"Fetch current weather for a city.\r\n\r\n    Args:\r\n        city: The city name to get weather for\r\n    \"\"\"\r\n    async with httpx.AsyncClient() as client:\r\n        response = await client.get(\r\n            f\"https:\u002F\u002Fwttr.in\u002F{city}?format=3\"\r\n        )\r\n        return response.text\r\n\r\nagent = Agent(\r\n    name=\"Weather Bot\",\r\n    instructions=\"Provide weather information.\",\r\n    tools=[fetch_weather]\r\n)\r\n```\r\n\r\n### Tool with Pydantic Types\r\n\r\n```python\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent, function_tool\r\n\r\nclass SearchQuery(BaseModel):\r\n    query: str\r\n    max_results: int = 10\r\n\r\nclass SearchResult(BaseModel):\r\n    title: str\r\n    url: str\r\n    snippet: str\r\n\r\n@function_tool\r\nasync def search_docs(params: SearchQuery) -> list[SearchResult]:\r\n    \"\"\"Search documentation for a query.\"\"\"\r\n    # Implementation\r\n    return [SearchResult(\r\n        title=\"Python Tutorial\",\r\n        url=\"https:\u002F\u002Fdocs.python.org\",\r\n        snippet=\"Official Python documentation...\"\r\n    )]\r\n\r\nagent = Agent(\r\n    name=\"Doc Search\",\r\n    instructions=\"Search Python documentation.\",\r\n    tools=[search_docs]\r\n)\r\n```\r\n\r\n## Multi-Agent Patterns\r\n\r\n### Handoffs (Recommended for Routing)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\n# Specialist agents\r\nconcepts_agent = Agent(\r\n    name=\"Concepts Tutor\",\r\n    handoff_description=\"Explains Python concepts and fundamentals\",\r\n    instructions=\"Explain Python concepts clearly with examples.\"\r\n)\r\n\r\ndebug_agent = Agent(\r\n    name=\"Debug Helper\",\r\n    handoff_description=\"Helps debug Python code errors\",\r\n    instructions=\"Help diagnose and fix Python errors.\"\r\n)\r\n\r\nexercise_agent = Agent(\r\n    name=\"Exercise Generator\",\r\n    handoff_description=\"Creates practice problems and exercises\",\r\n    instructions=\"Generate practice problems with solutions.\"\r\n)\r\n\r\n# Triage agent with handoffs\r\ntriage_agent = Agent(\r\n    name=\"Triage\",\r\n    instructions=\"\"\"Route student questions to the right specialist:\r\n    - Concepts questions → Concepts Tutor\r\n    - Error\u002Fbug questions → Debug Helper\r\n    - Practice requests → Exercise Generator\r\n\r\n    Analyze the question and hand off to the appropriate agent.\"\"\",\r\n    handoffs=[concepts_agent, debug_agent, exercise_agent]\r\n)\r\n\r\nasync def main():\r\n    # Question gets routed automatically\r\n    result = await Runner.run(\r\n        triage_agent,\r\n        \"I'm getting a KeyError in my dictionary code\"\r\n    )\r\n    print(result.final_output)  # Handled by debug_agent\r\n```\r\n\r\n### Agents as Tools (Orchestration)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\n# Create specialist agents\r\nresearcher = Agent(\r\n    name=\"Researcher\",\r\n    instructions=\"Research topics thoroughly.\"\r\n)\r\n\r\nwriter = Agent(\r\n    name=\"Writer\",\r\n    instructions=\"Write clear, engaging content.\"\r\n)\r\n\r\n# Manager uses agents as tools\r\nmanager = Agent(\r\n    name=\"Content Manager\",\r\n    instructions=\"\"\"Coordinate research and writing:\r\n    1. Use researcher tool to gather information\r\n    2. Use writer tool to create content\"\"\",\r\n    tools=[\r\n        researcher.as_tool(\r\n            tool_name=\"research\",\r\n            tool_description=\"Research a topic\"\r\n        ),\r\n        writer.as_tool(\r\n            tool_name=\"write\",\r\n            tool_description=\"Write content about a topic\"\r\n        )\r\n    ]\r\n)\r\n\r\nasync def main():\r\n    result = await Runner.run(\r\n        manager,\r\n        \"Create a blog post about async Python\"\r\n    )\r\n    print(result.final_output)\r\n```\r\n\r\n## Guardrails\r\n\r\n### Input Validation\r\n\r\n```python\r\nfrom agents import Agent, input_guardrail, GuardrailFunctionOutput\r\n\r\n@input_guardrail\r\nasync def check_homework_topic(context, agent, input_text: str) -> GuardrailFunctionOutput:\r\n    \"\"\"Ensure questions are homework-related.\"\"\"\r\n    keywords = [\"python\", \"code\", \"programming\", \"function\", \"class\", \"error\"]\r\n\r\n    if not any(kw in input_text.lower() for kw in keywords):\r\n        return GuardrailFunctionOutput(\r\n            output_info=\"Not a programming question\",\r\n            tripwire_triggered=True\r\n        )\r\n\r\n    return GuardrailFunctionOutput(\r\n        output_info=\"Valid programming question\",\r\n        tripwire_triggered=False\r\n    )\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Help with Python homework.\",\r\n    input_guardrails=[check_homework_topic]\r\n)\r\n```\r\n\r\n### Output Validation\r\n\r\n```python\r\nfrom agents import Agent, output_guardrail, GuardrailFunctionOutput\r\n\r\n@output_guardrail\r\nasync def check_no_solutions(context, agent, output: str) -> GuardrailFunctionOutput:\r\n    \"\"\"Ensure we don't give complete homework solutions.\"\"\"\r\n    solution_indicators = [\"here's the complete\", \"full solution\", \"copy this code\"]\r\n\r\n    if any(ind in output.lower() for ind in solution_indicators):\r\n        return GuardrailFunctionOutput(\r\n            output_info=\"Contains complete solution\",\r\n            tripwire_triggered=True\r\n        )\r\n\r\n    return GuardrailFunctionOutput(\r\n        output_info=\"Output is appropriate\",\r\n        tripwire_triggered=False\r\n    )\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Guide students without giving full solutions.\",\r\n    output_guardrails=[check_no_solutions]\r\n)\r\n```\r\n\r\n## Context Injection\r\n\r\n### Shared State Across Agents\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom agents import Agent, Runner, function_tool, RunContextWrapper\r\n\r\n@dataclass\r\nclass TutoringContext:\r\n    student_id: str\r\n    session_id: str\r\n    topics_covered: list[str]\r\n    difficulty_level: str = \"beginner\"\r\n\r\n@function_tool\r\ndef log_topic(wrapper: RunContextWrapper[TutoringContext], topic: str) -> str:\r\n    \"\"\"Log a topic as covered in this session.\"\"\"\r\n    wrapper.context.topics_covered.append(topic)\r\n    return f\"Logged: {topic}\"\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Teach Python, tracking topics covered.\",\r\n    tools=[log_topic]\r\n)\r\n\r\nasync def main():\r\n    ctx = TutoringContext(\r\n        student_id=\"student-123\",\r\n        session_id=\"session-456\",\r\n        topics_covered=[]\r\n    )\r\n\r\n    result = await Runner.run(\r\n        tutor,\r\n        \"Teach me about loops\",\r\n        context=ctx\r\n    )\r\n\r\n    print(f\"Topics covered: {ctx.topics_covered}\")\r\n```\r\n\r\n## Project Structure\r\n\r\n```\r\nlearnflow-agents\u002F\r\n├── agents\u002F\r\n│   ├── __init__.py\r\n│   ├── triage.py          # Routing agent\r\n│   ├── concepts.py        # Concepts specialist\r\n│   ├── debug.py           # Debug specialist\r\n│   └── exercise.py        # Exercise generator\r\n├── tools\u002F\r\n│   ├── __init__.py\r\n│   ├── code_runner.py     # Execute Python safely\r\n│   └── search.py          # Search documentation\r\n├── guardrails\u002F\r\n│   ├── __init__.py\r\n│   ├── input.py           # Input validation\r\n│   └── output.py          # Output validation\r\n├── main.py                # FastAPI integration\r\n└── pyproject.toml\r\n```\r\n\r\n## FastAPI Integration\r\n\r\n```python\r\nfrom fastapi import FastAPI, HTTPException\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent, Runner\r\n\r\napp = FastAPI()\r\n\r\n# Initialize agents\r\ntriage = Agent(\r\n    name=\"Triage\",\r\n    instructions=\"Route questions to specialists\",\r\n    handoffs=[concepts_agent, debug_agent]\r\n)\r\n\r\nclass Question(BaseModel):\r\n    text: str\r\n    session_id: str\r\n\r\nclass Answer(BaseModel):\r\n    response: str\r\n    agent_used: str\r\n\r\n@app.post(\"\u002Fask\", response_model=Answer)\r\nasync def ask_question(question: Question):\r\n    try:\r\n        result = await Runner.run(triage, question.text)\r\n        return Answer(\r\n            response=result.final_output,\r\n            agent_used=result.last_agent.name\r\n        )\r\n    except Exception as e:\r\n        raise HTTPException(status_code=500, detail=str(e))\r\n\r\n@app.post(\"\u002Fask\u002Fstream\")\r\nasync def ask_stream(question: Question):\r\n    from fastapi.responses import StreamingResponse\r\n\r\n    async def generate():\r\n        result = Runner.run_streamed(triage, question.text)\r\n        async for event in result.stream_events():\r\n            if hasattr(event, 'delta'):\r\n                yield event.delta\r\n\r\n    return StreamingResponse(generate(), media_type=\"text\u002Fplain\")\r\n```\r\n\r\n## Tracing & Debugging\r\n\r\n### View Traces\r\n\r\nTraces available at: https:\u002F\u002Fplatform.openai.com\u002Ftraces\r\n\r\n### Custom Tracing\r\n\r\n```python\r\nfrom agents import Runner, RunConfig\r\n\r\nconfig = RunConfig(\r\n    workflow_name=\"tutoring-session\",\r\n    trace_id=\"custom-trace-123\"\r\n)\r\n\r\nresult = await Runner.run(agent, \"Hello\", run_config=config)\r\n```\r\n\r\n## Verification\r\n\r\nRun: `python scripts\u002Fverify.py`\r\n\r\n## Related Skills\r\n\r\n- `configuring-dapr-pubsub` - Agent-to-agent messaging\r\n- `scaffolding-fastapi-dapr` - FastAPI backend integration\r\n- `streaming-llm-responses` - Response streaming patterns\r\n- `building-chat-interfaces` - Frontend chat UI","# Scaffolding OpenAI Agents\r\n\r\nBuild production AI agents using OpenAI Agents SDK with native async\u002Fawait patterns.\r\n\r\n## Quick Start\r\n\r\n```bash\r\n# Project setup\r\nmkdir my-agent && cd my-agent\r\npython -m venv .venv && source .venv\u002Fbin\u002Factivate\r\npip install openai-agents\r\n\r\n# Set API key\r\nexport OPENAI_API_KEY=sk-...\r\n```\r\n\r\n```python\r\n# main.py\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nagent = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"You help students learn Python. Explain concepts clearly with examples.\"\r\n)\r\n\r\nasync def main():\r\n    result = await Runner.run(agent, \"Explain list comprehensions\")\r\n    print(result.final_output)\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n## Agent Configuration\r\n\r\n### Basic Agent\r\n\r\n```python\r\nfrom agents import Agent\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"\"\"You are an expert Python tutor.\r\n    Explain concepts clearly with examples.\r\n    Ask clarifying questions when needed.\r\n    Provide practice exercises after explanations.\"\"\",\r\n    model=\"gpt-4o\"\r\n)\r\n```\r\n\r\n### With Model Settings\r\n\r\n```python\r\nfrom agents import Agent, ModelSettings\r\n\r\nagent = Agent(\r\n    name=\"Creative Writer\",\r\n    instructions=\"Write creative stories based on prompts.\",\r\n    model=\"gpt-4o\",\r\n    model_settings=ModelSettings(\r\n        temperature=0.9,\r\n        max_tokens=2000\r\n    )\r\n)\r\n```\r\n\r\n### With Structured Output\r\n\r\n```python\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent\r\n\r\nclass CodeReview(BaseModel):\r\n    issues: list[str]\r\n    suggestions: list[str]\r\n    score: int\r\n\r\nreviewer = Agent(\r\n    name=\"Code Reviewer\",\r\n    instructions=\"Review Python code for issues and improvements.\",\r\n    output_type=CodeReview  # Forces structured JSON output\r\n)\r\n```\r\n\r\n## Runner Patterns\r\n\r\n### Async Run (Primary)\r\n\r\n```python\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nasync def main():\r\n    agent = Agent(name=\"Helper\", instructions=\"Be helpful\")\r\n\r\n    # Single query\r\n    result = await Runner.run(agent, \"What is Python?\")\r\n    print(result.final_output)\r\n\r\n    # With conversation history\r\n    messages = [\r\n        {\"role\": \"user\", \"content\": \"My name is Alex\"},\r\n        {\"role\": \"assistant\", \"content\": \"Nice to meet you, Alex!\"},\r\n        {\"role\": \"user\", \"content\": \"What's my name?\"}\r\n    ]\r\n    result = await Runner.run(agent, messages)\r\n    print(result.final_output)  # \"Your name is Alex\"\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n### Sync Run (Simple Scripts)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\nagent = Agent(name=\"Helper\", instructions=\"Be helpful\")\r\nresult = Runner.run_sync(agent, \"Hello!\")\r\nprint(result.final_output)\r\n```\r\n\r\n### Streaming Run\r\n\r\n```python\r\nimport asyncio\r\nfrom agents import Agent, Runner\r\n\r\nasync def main():\r\n    agent = Agent(name=\"Storyteller\", instructions=\"Tell engaging stories\")\r\n\r\n    result = Runner.run_streamed(agent, \"Tell me a short story\")\r\n\r\n    async for event in result.stream_events():\r\n        if hasattr(event, 'delta'):\r\n            print(event.delta, end='', flush=True)\r\n\r\n    print()  # Newline at end\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n### Conversation Continuation\r\n\r\n```python\r\nasync def chat_session():\r\n    agent = Agent(name=\"Tutor\", instructions=\"You are a Python tutor\")\r\n\r\n    # First turn\r\n    result1 = await Runner.run(agent, \"Explain decorators\")\r\n    print(f\"Tutor: {result1.final_output}\")\r\n\r\n    # Continue conversation\r\n    messages = result1.to_input_list() + [\r\n        {\"role\": \"user\", \"content\": \"Show me an example\"}\r\n    ]\r\n    result2 = await Runner.run(agent, messages)\r\n    print(f\"Tutor: {result2.final_output}\")\r\n```\r\n\r\n## Function Tools\r\n\r\n### Basic Tool\r\n\r\n```python\r\nfrom agents import Agent, function_tool\r\n\r\n@function_tool\r\ndef get_current_time() -> str:\r\n    \"\"\"Get the current time.\"\"\"\r\n    from datetime import datetime\r\n    return datetime.now().strftime(\"%H:%M:%S\")\r\n\r\n@function_tool\r\ndef calculate(expression: str) -> float:\r\n    \"\"\"Calculate a mathematical expression.\r\n\r\n    Args:\r\n        expression: A valid Python math expression like \"2 + 2\" or \"10 * 5\"\r\n    \"\"\"\r\n    return eval(expression)  # Use safe_eval in production\r\n\r\nagent = Agent(\r\n    name=\"Assistant\",\r\n    instructions=\"Help with calculations and time queries.\",\r\n    tools=[get_current_time, calculate]\r\n)\r\n```\r\n\r\n### Async Tool\r\n\r\n```python\r\nimport httpx\r\nfrom agents import Agent, function_tool\r\n\r\n@function_tool\r\nasync def fetch_weather(city: str) -> str:\r\n    \"\"\"Fetch current weather for a city.\r\n\r\n    Args:\r\n        city: The city name to get weather for\r\n    \"\"\"\r\n    async with httpx.AsyncClient() as client:\r\n        response = await client.get(\r\n            f\"https:\u002F\u002Fwttr.in\u002F{city}?format=3\"\r\n        )\r\n        return response.text\r\n\r\nagent = Agent(\r\n    name=\"Weather Bot\",\r\n    instructions=\"Provide weather information.\",\r\n    tools=[fetch_weather]\r\n)\r\n```\r\n\r\n### Tool with Pydantic Types\r\n\r\n```python\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent, function_tool\r\n\r\nclass SearchQuery(BaseModel):\r\n    query: str\r\n    max_results: int = 10\r\n\r\nclass SearchResult(BaseModel):\r\n    title: str\r\n    url: str\r\n    snippet: str\r\n\r\n@function_tool\r\nasync def search_docs(params: SearchQuery) -> list[SearchResult]:\r\n    \"\"\"Search documentation for a query.\"\"\"\r\n    # Implementation\r\n    return [SearchResult(\r\n        title=\"Python Tutorial\",\r\n        url=\"https:\u002F\u002Fdocs.python.org\",\r\n        snippet=\"Official Python documentation...\"\r\n    )]\r\n\r\nagent = Agent(\r\n    name=\"Doc Search\",\r\n    instructions=\"Search Python documentation.\",\r\n    tools=[search_docs]\r\n)\r\n```\r\n\r\n## Multi-Agent Patterns\r\n\r\n### Handoffs (Recommended for Routing)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\n# Specialist agents\r\nconcepts_agent = Agent(\r\n    name=\"Concepts Tutor\",\r\n    handoff_description=\"Explains Python concepts and fundamentals\",\r\n    instructions=\"Explain Python concepts clearly with examples.\"\r\n)\r\n\r\ndebug_agent = Agent(\r\n    name=\"Debug Helper\",\r\n    handoff_description=\"Helps debug Python code errors\",\r\n    instructions=\"Help diagnose and fix Python errors.\"\r\n)\r\n\r\nexercise_agent = Agent(\r\n    name=\"Exercise Generator\",\r\n    handoff_description=\"Creates practice problems and exercises\",\r\n    instructions=\"Generate practice problems with solutions.\"\r\n)\r\n\r\n# Triage agent with handoffs\r\ntriage_agent = Agent(\r\n    name=\"Triage\",\r\n    instructions=\"\"\"Route student questions to the right specialist:\r\n    - Concepts questions → Concepts Tutor\r\n    - Error\u002Fbug questions → Debug Helper\r\n    - Practice requests → Exercise Generator\r\n\r\n    Analyze the question and hand off to the appropriate agent.\"\"\",\r\n    handoffs=[concepts_agent, debug_agent, exercise_agent]\r\n)\r\n\r\nasync def main():\r\n    # Question gets routed automatically\r\n    result = await Runner.run(\r\n        triage_agent,\r\n        \"I'm getting a KeyError in my dictionary code\"\r\n    )\r\n    print(result.final_output)  # Handled by debug_agent\r\n```\r\n\r\n### Agents as Tools (Orchestration)\r\n\r\n```python\r\nfrom agents import Agent, Runner\r\n\r\n# Create specialist agents\r\nresearcher = Agent(\r\n    name=\"Researcher\",\r\n    instructions=\"Research topics thoroughly.\"\r\n)\r\n\r\nwriter = Agent(\r\n    name=\"Writer\",\r\n    instructions=\"Write clear, engaging content.\"\r\n)\r\n\r\n# Manager uses agents as tools\r\nmanager = Agent(\r\n    name=\"Content Manager\",\r\n    instructions=\"\"\"Coordinate research and writing:\r\n    1. Use researcher tool to gather information\r\n    2. Use writer tool to create content\"\"\",\r\n    tools=[\r\n        researcher.as_tool(\r\n            tool_name=\"research\",\r\n            tool_description=\"Research a topic\"\r\n        ),\r\n        writer.as_tool(\r\n            tool_name=\"write\",\r\n            tool_description=\"Write content about a topic\"\r\n        )\r\n    ]\r\n)\r\n\r\nasync def main():\r\n    result = await Runner.run(\r\n        manager,\r\n        \"Create a blog post about async Python\"\r\n    )\r\n    print(result.final_output)\r\n```\r\n\r\n## Guardrails\r\n\r\n### Input Validation\r\n\r\n```python\r\nfrom agents import Agent, input_guardrail, GuardrailFunctionOutput\r\n\r\n@input_guardrail\r\nasync def check_homework_topic(context, agent, input_text: str) -> GuardrailFunctionOutput:\r\n    \"\"\"Ensure questions are homework-related.\"\"\"\r\n    keywords = [\"python\", \"code\", \"programming\", \"function\", \"class\", \"error\"]\r\n\r\n    if not any(kw in input_text.lower() for kw in keywords):\r\n        return GuardrailFunctionOutput(\r\n            output_info=\"Not a programming question\",\r\n            tripwire_triggered=True\r\n        )\r\n\r\n    return GuardrailFunctionOutput(\r\n        output_info=\"Valid programming question\",\r\n        tripwire_triggered=False\r\n    )\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Help with Python homework.\",\r\n    input_guardrails=[check_homework_topic]\r\n)\r\n```\r\n\r\n### Output Validation\r\n\r\n```python\r\nfrom agents import Agent, output_guardrail, GuardrailFunctionOutput\r\n\r\n@output_guardrail\r\nasync def check_no_solutions(context, agent, output: str) -> GuardrailFunctionOutput:\r\n    \"\"\"Ensure we don't give complete homework solutions.\"\"\"\r\n    solution_indicators = [\"here's the complete\", \"full solution\", \"copy this code\"]\r\n\r\n    if any(ind in output.lower() for ind in solution_indicators):\r\n        return GuardrailFunctionOutput(\r\n            output_info=\"Contains complete solution\",\r\n            tripwire_triggered=True\r\n        )\r\n\r\n    return GuardrailFunctionOutput(\r\n        output_info=\"Output is appropriate\",\r\n        tripwire_triggered=False\r\n    )\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Guide students without giving full solutions.\",\r\n    output_guardrails=[check_no_solutions]\r\n)\r\n```\r\n\r\n## Context Injection\r\n\r\n### Shared State Across Agents\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nfrom agents import Agent, Runner, function_tool, RunContextWrapper\r\n\r\n@dataclass\r\nclass TutoringContext:\r\n    student_id: str\r\n    session_id: str\r\n    topics_covered: list[str]\r\n    difficulty_level: str = \"beginner\"\r\n\r\n@function_tool\r\ndef log_topic(wrapper: RunContextWrapper[TutoringContext], topic: str) -> str:\r\n    \"\"\"Log a topic as covered in this session.\"\"\"\r\n    wrapper.context.topics_covered.append(topic)\r\n    return f\"Logged: {topic}\"\r\n\r\ntutor = Agent(\r\n    name=\"Python Tutor\",\r\n    instructions=\"Teach Python, tracking topics covered.\",\r\n    tools=[log_topic]\r\n)\r\n\r\nasync def main():\r\n    ctx = TutoringContext(\r\n        student_id=\"student-123\",\r\n        session_id=\"session-456\",\r\n        topics_covered=[]\r\n    )\r\n\r\n    result = await Runner.run(\r\n        tutor,\r\n        \"Teach me about loops\",\r\n        context=ctx\r\n    )\r\n\r\n    print(f\"Topics covered: {ctx.topics_covered}\")\r\n```\r\n\r\n## Project Structure\r\n\r\n```\r\nlearnflow-agents\u002F\r\n├── agents\u002F\r\n│   ├── __init__.py\r\n│   ├── triage.py          # Routing agent\r\n│   ├── concepts.py        # Concepts specialist\r\n│   ├── debug.py           # Debug specialist\r\n│   └── exercise.py        # Exercise generator\r\n├── tools\u002F\r\n│   ├── __init__.py\r\n│   ├── code_runner.py     # Execute Python safely\r\n│   └── search.py          # Search documentation\r\n├── guardrails\u002F\r\n│   ├── __init__.py\r\n│   ├── input.py           # Input validation\r\n│   └── output.py          # Output validation\r\n├── main.py                # FastAPI integration\r\n└── pyproject.toml\r\n```\r\n\r\n## FastAPI Integration\r\n\r\n```python\r\nfrom fastapi import FastAPI, HTTPException\r\nfrom pydantic import BaseModel\r\nfrom agents import Agent, Runner\r\n\r\napp = FastAPI()\r\n\r\n# Initialize agents\r\ntriage = Agent(\r\n    name=\"Triage\",\r\n    instructions=\"Route questions to specialists\",\r\n    handoffs=[concepts_agent, debug_agent]\r\n)\r\n\r\nclass Question(BaseModel):\r\n    text: str\r\n    session_id: str\r\n\r\nclass Answer(BaseModel):\r\n    response: str\r\n    agent_used: str\r\n\r\n@app.post(\"\u002Fask\", response_model=Answer)\r\nasync def ask_question(question: Question):\r\n    try:\r\n        result = await Runner.run(triage, question.text)\r\n        return Answer(\r\n            response=result.final_output,\r\n            agent_used=result.last_agent.name\r\n        )\r\n    except Exception as e:\r\n        raise HTTPException(status_code=500, detail=str(e))\r\n\r\n@app.post(\"\u002Fask\u002Fstream\")\r\nasync def ask_stream(question: Question):\r\n    from fastapi.responses import StreamingResponse\r\n\r\n    async def generate():\r\n        result = Runner.run_streamed(triage, question.text)\r\n        async for event in result.stream_events():\r\n            if hasattr(event, 'delta'):\r\n                yield event.delta\r\n\r\n    return StreamingResponse(generate(), media_type=\"text\u002Fplain\")\r\n```\r\n\r\n## Tracing & Debugging\r\n\r\n### View Traces\r\n\r\nTraces available at: https:\u002F\u002Fplatform.openai.com\u002Ftraces\r\n\r\n### Custom Tracing\r\n\r\n```python\r\nfrom agents import Runner, RunConfig\r\n\r\nconfig = RunConfig(\r\n    workflow_name=\"tutoring-session\",\r\n    trace_id=\"custom-trace-123\"\r\n)\r\n\r\nresult = await Runner.run(agent, \"Hello\", run_config=config)\r\n```\r\n\r\n## Verification\r\n\r\nRun: `python scripts\u002Fverify.py`\r\n\r\n## Related Skills\r\n\r\n- `configuring-dapr-pubsub` - Agent-to-agent messaging\r\n- `scaffolding-fastapi-dapr` - FastAPI backend integration\r\n- `streaming-llm-responses` - Response streaming patterns\r\n- `building-chat-interfaces` - Frontend chat UI",{"name":5,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fasmayaseen\u002Fscaffolding-openai-agents",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill scaffolding-openai-agents",{"tool":59,"command":60},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill scaffolding-openai-agents",{"tool":62,"command":63},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill scaffolding-openai-agents","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fasmayaseen\u002Fscaffolding-openai-agents\u002FSKILL.md",true,[67,73],{"path":68,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":71,"sourceHtmlUrl":72},"scripts\u002Fverify.py","SCRIPT","脚本",1170,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fasmayaseen\u002Fscaffolding-openai-agents\u002Fscripts\u002Fverify.py",{"path":74,"resourceType":75,"resourceTypeDesc":76,"sizeBytes":77,"sourceHtmlUrl":78},"skill-report.json","REFERENCE","参考文档",9928,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fasmayaseen\u002Fscaffolding-openai-agents\u002Fskill-report.json",[80,89,98,107,113,119],{"skillNo":81,"name":82,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":39},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[86,87,88],"model","model hierarchy","model hierarchy skill",{"skillNo":90,"name":91,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":39},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[95,96,97],"MCP","zoom","zoom mcp",{"skillNo":99,"name":100,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":39},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[104,105,106,96],"sdk","zoom apps sdk","apps",{"skillNo":108,"name":109,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":39},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[109],{"skillNo":114,"name":115,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":39},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[115],{"skillNo":120,"name":121,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":39},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[121]]