()
| 50 | |
| 51 | |
| 52 | async def main(): |
| 53 | print("🚀 Testing Pydantic Argument Feature") |
| 54 | print("=" * 50) |
| 55 | |
| 56 | runner = InMemoryRunner( |
| 57 | agent=agent.root_agent, |
| 58 | app_name=APP_NAME, |
| 59 | ) |
| 60 | |
| 61 | # Create a session |
| 62 | session = await runner.session_service.create_session( |
| 63 | app_name=APP_NAME, user_id=USER_ID |
| 64 | ) |
| 65 | |
| 66 | test_prompts = [ |
| 67 | # Test Optional[Pydantic] type handling (UserProfile + Optional[UserPreferences]) |
| 68 | ( |
| 69 | "Create an account for Alice, 25 years old, email: alice@example.com," |
| 70 | " with dark theme and Spanish language preferences" |
| 71 | ), |
| 72 | ( |
| 73 | "Create a user account for Bob, age 30, no email, " |
| 74 | "with light theme, French language, and notifications disabled" |
| 75 | ), |
| 76 | ( |
| 77 | "Make an account for Charlie, 28 years old, email: charlie@test.com, " |
| 78 | "but use default preferences" |
| 79 | ), |
| 80 | # Test Union type handling (Union[UserProfile, CompanyProfile]) |
| 81 | ( |
| 82 | "Create a profile for Tech Corp company, software industry, " |
| 83 | "with 150 employees and website techcorp.com" |
| 84 | ), |
| 85 | ( |
| 86 | "Create an entity profile for Diana, 32 years old, " |
| 87 | "email diana@example.com" |
| 88 | ), |
| 89 | ] |
| 90 | |
| 91 | for i, prompt in enumerate(test_prompts, 1): |
| 92 | print(f"\n📝 Test {i}: {prompt}") |
| 93 | print("-" * 40) |
| 94 | |
| 95 | try: |
| 96 | response = await call_agent_async(runner, USER_ID, session.id, prompt) |
| 97 | print(f"✅ Response: {response}") |
| 98 | except Exception as e: |
| 99 | print(f"❌ Error: {e}") |
| 100 | |
| 101 | print("\n" + "=" * 50) |
| 102 | print("✨ Testing complete!") |
| 103 | print("🔧 Features demonstrated:") |
| 104 | print(" • JSON dict → Pydantic model conversion (UserProfile)") |
| 105 | print(" • Optional type handling (Optional[UserPreferences])") |
| 106 | print(" • Union type handling (Union[UserProfile, CompanyProfile])") |
| 107 | print(" • Automatic model validation and conversion") |
| 108 | print(" • No manual isinstance() checks needed!") |
| 109 |
no test coverage detected