()
| 72 | |
| 73 | |
| 74 | async def run_code_interpreter_demo(): |
| 75 | agent = Agent( |
| 76 | name="Code interpreter", |
| 77 | instructions="You love doing math.", |
| 78 | tools=[ |
| 79 | CodeInterpreterTool( |
| 80 | tool_config={"type": "code_interpreter", "container": {"type": "auto"}}, |
| 81 | ) |
| 82 | ], |
| 83 | ) |
| 84 | |
| 85 | with trace("Code interpreter example"): |
| 86 | print("Solving math problem...") |
| 87 | result = Runner.run_streamed(agent, "What is the square root of 273 * 312821 plus 1782?") |
| 88 | async for event in result.stream_events(): |
| 89 | if ( |
| 90 | event.type == "run_item_stream_event" |
| 91 | and event.item.type == "tool_call_item" |
| 92 | and event.item.raw_item.type == "code_interpreter_call" |
| 93 | ): |
| 94 | print(f"Code interpreter code:\n```\n{event.item.raw_item.code}\n```\n") |
| 95 | elif event.type == "run_item_stream_event": |
| 96 | print(f"Other event: {event.item.type}") |
| 97 | |
| 98 | print(f"Final output: {result.final_output}") |
| 99 | |
| 100 | |
| 101 | # Run the demo |
no test coverage detected
searching dependent graphs…