/ examples / caching / 00_agent_caching_basic.py
00_agent_caching_basic.py
 1  """
 2  Basic Caching Configuration Example
 3  
 4  Demonstrates using caching for response and prompt caching.
 5  """
 6  import os
 7  from praisonaiagents import Agent, CachingConfig
 8  
 9  # Ensure API key is set from environment
10  assert os.getenv("OPENAI_API_KEY"), "OPENAI_API_KEY must be set"
11  
12  # Default caching (enabled)
13  agent_cached = Agent(
14      instructions="You are a helpful assistant.",
15      caching=True,
16  )
17  
18  # Disable caching
19  agent_no_cache = Agent(
20      instructions="You are a helpful assistant.",
21      caching=False,
22  )
23  
24  # Custom caching configuration
25  agent_custom = Agent(
26      instructions="You are a helpful assistant.",
27      caching=CachingConfig(
28          enabled=True,
29          prompt_caching=True,  # Enable prompt caching for supported providers
30      ),
31  )
32  
33  if __name__ == "__main__":
34      print("Testing CachingConfig...")
35      
36      print(f"Cached agent cache: {agent_cached.cache}")
37      print(f"No-cache agent cache: {agent_no_cache.cache}")
38      print(f"Custom agent cache: {agent_custom.cache}")
39      
40      result = agent_cached.chat("What is caching?")
41      print(f"Result: {result}")
42      
43      print("\nCachingConfig tests passed!")