Response caching and execution limits

Cut repeat LLM spend with CachingConfig and ExecutionConfig

During development and in FAQ-heavy production apps, users repeatedly ask identical questions. Combine CachingConfig(enabled=True, prompt_caching=True) with ExecutionConfig(max_iter=5, max_budget=0.10, context_compaction=True) to stay fast and budget-safe.

Example

from praisonai import Agent, CachingConfig, ExecutionConfig

faq_agent = Agent(
    name='CachedFAQ',
    instructions='Answer in one concise sentence.',
    caching=CachingConfig(enabled=True, prompt_caching=True),
    execution=ExecutionConfig(max_iter=3, max_rpm=30, max_budget=0.10, context_compaction=True),
    output='silent',
)
print(faq_agent.start('Why does response caching save money on repeated FAQ questions?'))

Try it Yourself

Example explained

  • CachingConfig(enabled=True, prompt_caching=True) — Reuses cached completions and long system-prompt prefixes to cut latency and token cost.
  • ExecutionConfig(max_iter=5, max_rpm=30, max_budget=0.10) — Protects your account with hard iteration, rate, and dollar ceilings.

Always pass context_compaction=True explicitly

Setting context_compaction=True proactively protects long agent loops from context-overflow crashes while keeping behavior explicit across SDK upgrades.

Common pitfall: caching time-sensitive live tool answers

Turn off response caching on agents that answer live stock prices, weather, or real-time order statuses so users never receive stale cached replies.

Reference: documentation