| | import asyncio |
| | import os |
| | import sys |
| | from pathlib import Path |
| |
|
| | from dotenv import load_dotenv |
| |
|
| | |
| | parent_dir = Path(__file__).parent.parent |
| | sys.path.insert(0, str(parent_dir)) |
| |
|
| | from langgraph_agent import AgentFactory |
| | from agent_cache import get_or_create_agent, get_cache_stats |
| |
|
| | async def test_cache(): |
| | |
| | session_id = "test_session_123" |
| | openai_key = os.environ.get("OPENAI_API_KEY") |
| |
|
| | |
| | if not openai_key: |
| | print("❌ OPENAI_API_KEY environment variable not set!") |
| | print("Please set your OpenAI API key to run this test.") |
| | print("Example: export OPENAI_API_KEY='sk-your-key-here'") |
| | return |
| |
|
| | print("="*50) |
| | print("[TEST 1]: Create agent (cache miss)") |
| | print("="*50) |
| |
|
| | agent1 = await get_or_create_agent( |
| | session_id=session_id, |
| | provider="openai", |
| | api_key=openai_key, |
| | model="gpt-4o-mini", |
| | mode="Specialized Subagents (3 Specialists)", |
| | agent_factory_method=lambda: AgentFactory.create_subagent_orchestrator( |
| | model="gpt-4o-mini", |
| | api_key=openai_key, |
| | provider="openai", |
| | mode="Specialized Subagents (3 Specialists)" |
| | ) |
| | ) |
| |
|
| | print(f"\nCache stats: {get_cache_stats()}") |
| |
|
| | print("\n"+"="*50) |
| | print("[TEST 2: Get same agent (cache hit)") |
| | print("="*50) |
| |
|
| | agent2 = await get_or_create_agent( |
| | session_id=session_id, |
| | provider="openai", |
| | api_key=openai_key, |
| | model="gpt-4o-mini", |
| | mode="Specialized Subagents (3 Specialists)", |
| | agent_factory_method=lambda: AgentFactory.create_subagent_orchestrator( |
| | model="gpt-4o-mini", |
| | api_key=openai_key, |
| | provider="openai", |
| | mode="Specialized Subagents (3 Specialists)" |
| | ) |
| | ) |
| |
|
| | print(f"\nCache stats: {get_cache_stats()}") |
| |
|
| | |
| | print(f"\nSame agent object? {agent1 is agent2}") |
| |
|
| | print("\n"+"="*50) |
| | print("[TEST 3]: Different session (cache miss)") |
| | print("=" * 50) |
| |
|
| | agent3 = await get_or_create_agent( |
| | session_id="different_session_456", |
| | provider="openai", |
| | api_key=openai_key, |
| | model="gpt-4o-mini", |
| | mode="Specialized Subagents (3 Specialists)", |
| | agent_factory_method=lambda: AgentFactory.create_subagent_orchestrator( |
| | model="gpt-4o-mini", |
| | api_key=openai_key, |
| | provider="openai", |
| | mode="Specialized Subagents (3 Specialists)" |
| | ) |
| | ) |
| |
|
| | print(f"\nCache stats: {get_cache_stats()}") |
| |
|
| | asyncio.run(test_cache()) |