|
106 | 106 | "source": [ |
107 | 107 | "import random\n", |
108 | 108 | "import uuid\n", |
109 | | - "from pydantic import BaseModel\n", |
110 | 109 | "\n", |
111 | 110 | "# OpenAI Agents SDK imports\n", |
112 | 111 | "from agents import (\n", |
113 | 112 | " Agent,\n", |
114 | 113 | " HandoffOutputItem,\n", |
115 | 114 | " ItemHelpers,\n", |
116 | 115 | " MessageOutputItem,\n", |
117 | | - " Runner,\n", |
118 | 116 | " RunContextWrapper,\n", |
| 117 | + " Runner,\n", |
119 | 118 | " ToolCallItem,\n", |
120 | 119 | " ToolCallOutputItem,\n", |
121 | 120 | " function_tool,\n", |
122 | 121 | " handoff,\n", |
123 | | - " trace as agent_trace,\n", |
124 | 122 | " set_trace_processors,\n", |
125 | 123 | ")\n", |
| 124 | + "from agents import trace as agent_trace\n", |
126 | 125 | "from agents.extensions.handoff_prompt import RECOMMENDED_PROMPT_PREFIX\n", |
| 126 | + "from pydantic import BaseModel\n", |
127 | 127 | "\n", |
128 | 128 | "# Openlayer integration\n", |
129 | 129 | "from openlayer.lib.integrations.openai_agents import OpenlayerTracerProcessor\n" |
|
155 | 155 | " version=\"1.0.0\",\n", |
156 | 156 | " environment=\"development\"\n", |
157 | 157 | " )\n", |
158 | | - "])\n", |
159 | | - "\n", |
160 | | - "print(\"✅ Openlayer tracing configured successfully!\")\n" |
| 158 | + "])" |
161 | 159 | ] |
162 | 160 | }, |
163 | 161 | { |
|
184 | 182 | " passenger_name: str | None = None\n", |
185 | 183 | " confirmation_number: str | None = None\n", |
186 | 184 | " seat_number: str | None = None\n", |
187 | | - " flight_number: str | None = None\n", |
188 | | - "\n", |
189 | | - "print(\"✅ Context model defined!\")\n" |
| 185 | + " flight_number: str | None = None\n" |
190 | 186 | ] |
191 | 187 | }, |
192 | 188 | { |
|
249 | 245 | " context.context.seat_number = new_seat\n", |
250 | 246 | " # Ensure that the flight number has been set by the incoming handoff\n", |
251 | 247 | " assert context.context.flight_number is not None, \"Flight number is required\"\n", |
252 | | - " return f\"Updated seat to {new_seat} for confirmation number {confirmation_number}\"\n", |
253 | | - "\n", |
254 | | - "print(\"✅ Function tools created!\")\n" |
| 248 | + " return f\"Updated seat to {new_seat} for confirmation number {confirmation_number}\"" |
255 | 249 | ] |
256 | 250 | }, |
257 | 251 | { |
|
277 | 271 | " \"\"\"Hook that runs when handing off to the seat booking agent.\"\"\"\n", |
278 | 272 | " # Generate a random flight number when booking seats\n", |
279 | 273 | " flight_number = f\"FLT-{random.randint(100, 999)}\"\n", |
280 | | - " context.context.flight_number = flight_number\n", |
281 | | - " print(f\"🎫 Generated flight number: {flight_number}\")\n", |
282 | | - "\n", |
283 | | - "print(\"✅ Hook functions created!\")\n" |
| 274 | + " context.context.flight_number = flight_number" |
284 | 275 | ] |
285 | 276 | }, |
286 | 277 | { |
|
347 | 338 | "\n", |
348 | 339 | "# Set up bidirectional handoffs (agents can return to triage)\n", |
349 | 340 | "faq_agent.handoffs.append(triage_agent)\n", |
350 | | - "seat_booking_agent.handoffs.append(triage_agent)\n", |
351 | | - "\n", |
352 | | - "print(\"✅ All agents created and configured!\")\n", |
353 | | - "print(f\"👥 Agents: {triage_agent.name}, {faq_agent.name}, {seat_booking_agent.name}\")\n" |
| 341 | + "seat_booking_agent.handoffs.append(triage_agent)\n" |
354 | 342 | ] |
355 | 343 | }, |
356 | 344 | { |
|
380 | 368 | " current_agent = triage_agent\n", |
381 | 369 | " context = AirlineAgentContext()\n", |
382 | 370 | "\n", |
383 | | - " print(f\"🎯 Starting conversation with ID: {conversation_id}\")\n", |
384 | | - " print(f\"💬 Processing user input: '{user_input}'\")\n", |
385 | | - "\n", |
386 | 371 | " responses = []\n", |
387 | 372 | "\n", |
388 | 373 | " # Wrap the agent execution in a trace for Openlayer monitoring\n", |
389 | 374 | " with agent_trace(\"Customer service\", group_id=conversation_id):\n", |
390 | | - " print(\"🔍 Inside agent trace context\")\n", |
391 | | - " print(f\"🤖 Running agent: {current_agent.name}\")\n", |
392 | | - "\n", |
393 | 375 | " result = await Runner.run(current_agent, user_input, context=context)\n", |
394 | | - " print(f\"✅ Agent execution completed, got {len(result.new_items)} items\")\n", |
395 | 376 | "\n", |
396 | 377 | " # Process the results\n", |
397 | 378 | " for new_item in result.new_items:\n", |
|
410 | 391 | " else:\n", |
411 | 392 | " responses.append(f\"{agent_name}: {new_item.__class__.__name__}\")\n", |
412 | 393 | "\n", |
413 | | - " print(\"📤 Exiting agent trace context - spans should be queued for export\")\n", |
414 | | - "\n", |
415 | | - " return \"\\n\".join(responses)\n", |
416 | | - "\n", |
417 | | - "print(\"✅ Conversation runner created!\")\n" |
| 394 | + " return \"\\n\".join(responses)\n" |
418 | 395 | ] |
419 | 396 | }, |
420 | 397 | { |
|
440 | 417 | "source": [ |
441 | 418 | "# Test FAQ functionality\n", |
442 | 419 | "response = await run_conversation(\"What are the baggage restrictions?\")\n", |
443 | | - "print(\"🎒 Baggage Query Response:\")\n", |
444 | | - "print(response)\n", |
445 | | - "print(\"\\n\" + \"=\"*50 + \"\\n\")\n" |
| 420 | + "response\n" |
446 | 421 | ] |
447 | 422 | }, |
448 | 423 | { |
|
464 | 439 | "source": [ |
465 | 440 | "# Test seat booking functionality\n", |
466 | 441 | "response = await run_conversation(\"I want to change my seat\")\n", |
467 | | - "print(\"💺 Seat Change Request Response:\")\n", |
468 | | - "print(response)\n", |
469 | | - "print(\"\\n\" + \"=\"*50 + \"\\n\")\n" |
| 442 | + "response\n" |
470 | 443 | ] |
471 | 444 | }, |
472 | 445 | { |
|
488 | 461 | "source": [ |
489 | 462 | "# Test a more complex interaction\n", |
490 | 463 | "response = await run_conversation(\"I need help with my flight. Can you tell me about the seats and also help me change mine?\")\n", |
491 | | - "print(\"🛫 Complex Query Response:\")\n", |
492 | | - "print(response)\n", |
493 | | - "print(\"\\n\" + \"=\"*50 + \"\\n\")\n" |
| 464 | + "response\n" |
494 | 465 | ] |
495 | 466 | }, |
496 | 467 | { |
|
0 commit comments