Repository navigation
Recording a PraisonAI agent and replaying it offline — and the env-var precedence that surprised me #5063
xizhuomengcontin
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I maintain OrcaReplay (Apache-2.0), which records an agent run from outside the process and can serve the recording back so the run happens again with no provider called. I ran it against PraisonAI this evening. It works with no changes to your agent code — and on the way I found one thing about PraisonAI's own plumbing that is worth knowing if you ever point it at a local endpoint.
The finding: PraisonAI resolves the origin itself, and
OPENAI_API_BASEwinsThe OpenAI Python SDK only reads
OPENAI_BASE_URL. PraisonAI does not delegate that decision —praisonaiagents/llm/openai_client.pyresolves it by hand, with its own precedence:So
OPENAI_API_BASEtakes precedence overOPENAI_BASE_URLhere, which is the opposite way round from what someone who has only used the SDK would assume. If both are set — and they often both are, because different tools set different ones — PraisonAI silently usesOPENAI_API_BASE. I went in expecting the SDK's behaviour and would have been debugging the wrong variable if the two had disagreed.(There is a second, smaller one right next to it: the module-level client is cached on the normalized
api_key+base_url+ retry triple, so changing the environment variable inside a running process does not necessarily get you a new client. Fine in practice, surprising if you are switching endpoints mid-run.)Worth saying plainly: this is not a bug report. Explicit resolution with a documented order is a defensible choice, and the error message at line 392 already nudges people toward
OPENAI_API_BASEfor local servers. It is just undocumented in the README, and it is exactly the kind of thing that costs someone an hour.Recording a PraisonAI agent
Nothing is imported into your agent.
orca recordlaunches your script as a child process with the provider origin redirected for that process only:npm i -g orcareplay # Node 20+ orca record generic-openai -- python my_agent.pyThen kill the network and run it again:
exact=1means the replayed request matched the recorded one byte for byte — instructions, message assembly and parameters all reproduced — and the origin process was killed before the replay, so nothing could have quietly reached the network. PraisonAI's own agent loop and tool dispatch run for real; only the model's answer comes from the trace.Why that is useful here specifically: a PraisonAI workflow that misbehaves on the fourth step becomes something a maintainer can reproduce without your API key and without spending anything, and the same recording runs in CI as a regression test for instruction or tool changes.
Tested against
praisonaiagentson Python 3.12, with a deterministic local origin standing in for a provider.Two limits, stated rather than buried
egress=blockedmeans model-provider egress, not network isolation. Replay stops the model call, but your agent's tools still run for real — a tool that fetches a URL fetches it again, and withtools_run_on=the sandbox is still doing real work. It is not a sandbox.Happy to open a docs PR for the
OPENAI_API_BASEprecedence note if that would be useful — say the word rather than me adding noise to your PR queue.All reactions