()
| 20 | |
| 21 | |
| 22 | async def main(): |
| 23 | # Create an agent |
| 24 | agent = Agent( |
| 25 | name="Assistant", |
| 26 | instructions="Reply very concisely.", |
| 27 | tools=[get_weather], |
| 28 | ) |
| 29 | |
| 30 | # Create an advanced session instance |
| 31 | session = AdvancedSQLiteSession( |
| 32 | session_id="conversation_comprehensive", |
| 33 | create_tables=True, |
| 34 | ) |
| 35 | |
| 36 | print("=== AdvancedSQLiteSession Comprehensive Example ===") |
| 37 | print("This example demonstrates both basic and advanced session features.\n") |
| 38 | |
| 39 | # === PART 1: Basic Session Functionality === |
| 40 | print("=== PART 1: Basic Session Memory ===") |
| 41 | print("The agent will remember previous messages with structured tracking.\n") |
| 42 | |
| 43 | # First turn |
| 44 | print("First turn:") |
| 45 | print("User: What city is the Golden Gate Bridge in?") |
| 46 | result = await Runner.run( |
| 47 | agent, |
| 48 | "What city is the Golden Gate Bridge in?", |
| 49 | session=session, |
| 50 | ) |
| 51 | print(f"Assistant: {result.final_output}") |
| 52 | print(f"Usage: {result.context_wrapper.usage.total_tokens} tokens") |
| 53 | |
| 54 | # Store usage data automatically |
| 55 | await session.store_run_usage(result) |
| 56 | print() |
| 57 | |
| 58 | # Second turn - continuing the conversation |
| 59 | print("Second turn:") |
| 60 | print("User: What's the weather in that city?") |
| 61 | result = await Runner.run( |
| 62 | agent, |
| 63 | "What's the weather in that city?", |
| 64 | session=session, |
| 65 | ) |
| 66 | print(f"Assistant: {result.final_output}") |
| 67 | print(f"Usage: {result.context_wrapper.usage.total_tokens} tokens") |
| 68 | |
| 69 | # Store usage data automatically |
| 70 | await session.store_run_usage(result) |
| 71 | print() |
| 72 | |
| 73 | # Third turn |
| 74 | print("Third turn:") |
| 75 | print("User: What's the population of that city?") |
| 76 | result = await Runner.run( |
| 77 | agent, |
| 78 | "What's the population of that city?", |
| 79 | session=session, |
no test coverage detected