|
78 | 78 | "import os\n", |
79 | 79 | "\n", |
80 | 80 | "# Set up OpenAI API key\n", |
81 | | - "os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\" # Replace with your actual OpenAI API key\n", |
| 81 | + "os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n", |
82 | 82 | "\n", |
83 | 83 | "# Set up Openlayer environment variables\n", |
84 | | - "os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\" # Replace with your actual pipeline ID\n", |
85 | | - "os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\" # Replace with your actual Openlayer API key\n" |
| 84 | + "os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\"\n", |
| 85 | + "os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n" |
86 | 86 | ] |
87 | 87 | }, |
88 | 88 | { |
|
104 | 104 | "metadata": {}, |
105 | 105 | "outputs": [], |
106 | 106 | "source": [ |
107 | | - "import asyncio\n", |
108 | 107 | "import random\n", |
109 | 108 | "import uuid\n", |
110 | | - "import logging\n", |
111 | 109 | "from pydantic import BaseModel\n", |
112 | 110 | "\n", |
113 | 111 | "# OpenAI Agents SDK imports\n", |
|
211 | 209 | "outputs": [], |
212 | 210 | "source": [ |
213 | 211 | "@function_tool(\n", |
214 | | - " name_override=\"faq_lookup_tool\", \n", |
| 212 | + " name_override=\"faq_lookup_tool\",\n", |
215 | 213 | " description_override=\"Lookup frequently asked questions.\"\n", |
216 | 214 | ")\n", |
217 | 215 | "async def faq_lookup_tool(question: str) -> str:\n", |
|
235 | 233 | "\n", |
236 | 234 | "@function_tool\n", |
237 | 235 | "async def update_seat(\n", |
238 | | - " context: RunContextWrapper[AirlineAgentContext], \n", |
239 | | - " confirmation_number: str, \n", |
| 236 | + " context: RunContextWrapper[AirlineAgentContext],\n", |
| 237 | + " confirmation_number: str,\n", |
240 | 238 | " new_seat: str\n", |
241 | 239 | ") -> str:\n", |
242 | 240 | " \"\"\"\n", |
243 | 241 | " Update the seat for a given confirmation number.\n", |
244 | | - " \n", |
| 242 | + "\n", |
245 | 243 | " Args:\n", |
246 | 244 | " confirmation_number: The confirmation number for the flight.\n", |
247 | 245 | " new_seat: The new seat to update to.\n", |
|
378 | 376 | " \"\"\"Run a single conversation turn with the agent system.\"\"\"\n", |
379 | 377 | " if conversation_id is None:\n", |
380 | 378 | " conversation_id = uuid.uuid4().hex[:16]\n", |
381 | | - " \n", |
| 379 | + "\n", |
382 | 380 | " current_agent = triage_agent\n", |
383 | 381 | " context = AirlineAgentContext()\n", |
384 | | - " \n", |
| 382 | + "\n", |
385 | 383 | " print(f\"🎯 Starting conversation with ID: {conversation_id}\")\n", |
386 | 384 | " print(f\"💬 Processing user input: '{user_input}'\")\n", |
387 | | - " \n", |
| 385 | + "\n", |
388 | 386 | " responses = []\n", |
389 | | - " \n", |
| 387 | + "\n", |
390 | 388 | " # Wrap the agent execution in a trace for Openlayer monitoring\n", |
391 | 389 | " with agent_trace(\"Customer service\", group_id=conversation_id):\n", |
392 | 390 | " print(\"🔍 Inside agent trace context\")\n", |
393 | 391 | " print(f\"🤖 Running agent: {current_agent.name}\")\n", |
394 | | - " \n", |
| 392 | + "\n", |
395 | 393 | " result = await Runner.run(current_agent, user_input, context=context)\n", |
396 | 394 | " print(f\"✅ Agent execution completed, got {len(result.new_items)} items\")\n", |
397 | | - " \n", |
| 395 | + "\n", |
398 | 396 | " # Process the results\n", |
399 | 397 | " for new_item in result.new_items:\n", |
400 | 398 | " agent_name = new_item.agent.name\n", |
401 | | - " \n", |
| 399 | + "\n", |
402 | 400 | " if isinstance(new_item, MessageOutputItem):\n", |
403 | 401 | " message = ItemHelpers.text_message_output(new_item)\n", |
404 | 402 | " responses.append(f\"{agent_name}: {message}\")\n", |
|
411 | 409 | " responses.append(f\"{agent_name}: Tool call output: {new_item.output}\")\n", |
412 | 410 | " else:\n", |
413 | 411 | " responses.append(f\"{agent_name}: {new_item.__class__.__name__}\")\n", |
414 | | - " \n", |
| 412 | + "\n", |
415 | 413 | " print(\"📤 Exiting agent trace context - spans should be queued for export\")\n", |
416 | | - " \n", |
| 414 | + "\n", |
417 | 415 | " return \"\\n\".join(responses)\n", |
418 | 416 | "\n", |
419 | 417 | "print(\"✅ Conversation runner created!\")\n" |
|
494 | 492 | "print(response)\n", |
495 | 493 | "print(\"\\n\" + \"=\"*50 + \"\\n\")\n" |
496 | 494 | ] |
| 495 | + }, |
| 496 | + { |
| 497 | + "cell_type": "code", |
| 498 | + "execution_count": null, |
| 499 | + "metadata": {}, |
| 500 | + "outputs": [], |
| 501 | + "source": [] |
497 | 502 | } |
498 | 503 | ], |
499 | 504 | "metadata": { |
500 | 505 | "kernelspec": { |
501 | | - "display_name": ".venv", |
| 506 | + "display_name": "agents", |
502 | 507 | "language": "python", |
503 | 508 | "name": "python3" |
504 | 509 | }, |
|
512 | 517 | "name": "python", |
513 | 518 | "nbconvert_exporter": "python", |
514 | 519 | "pygments_lexer": "ipython3", |
515 | | - "version": "3.10.16" |
| 520 | + "version": "3.10.14" |
516 | 521 | } |
517 | 522 | }, |
518 | 523 | "nbformat": 4, |
|
0 commit comments