Offline testing with ScriptedModel and limits
Test agents offline for $0 with ScriptedModel
Running automated tests against live LLMs is slow, flaky, and costs money. PraisonAI ships ScriptedModel and no_model_requests right inside praisonai so your CI tests run in milliseconds with zero network calls.
Pass ScriptedModel([…]) as the Agent's model inside with no_model_requests(): — you should see 'Approved: order #42 is ready.' and 1 recorded request with zero external API calls.
Example
from praisonai import Agent, ScriptedModel, no_model_requests
model = ScriptedModel(['Approved: order #42 is ready.'])
agent = Agent(instructions='Be concise.', model=model)
with no_model_requests():
reply = agent.start('Check order 42')
print(reply)
print('Requests recorded:', model.request_count)Example explained
- ScriptedModel([…]) — Replays deterministic test replies through the real Agent execution path without calling any live LLM API.
- Agent(…, model=model) — Wires the offline test double directly into your real Agent.
- with no_model_requests(): — Hard-blocks accidental real network requests during automated tests.
Cap steps and retries with ExecutionConfig
In production, pair guardrails with ExecutionConfig(max_steps=…, max_budget=…) so a confused tool loop can never run forever or burn your budget.
Expected output: the agent completes within the configured step cap.
Example
from praisonai import Agent, ExecutionConfig
agent = Agent(
instructions='Be brief.',
execution=ExecutionConfig(max_steps=5),
)
print(agent.start('Give one sentence on why step limits matter.'))Example explained
- ExecutionConfig(max_steps=5) — Caps the maximum reasoning and tool iterations allowed for a single run.
Reference: documentation