Skip to content

Run an agent from a script ​

Last updated Nov 30, 2026 View as Markdown

Run the example agent reviewer from a script and read its answer and its session ID. A script has no terminal to ask on, so fetch the agent and approve it once beforehand; pandra pull shows what the agent contains:

terminal
sh
pandra pull github.com/pandra-io/pandra/examples/reviewer
pandra agent trust github.com/pandra-io/pandra/examples/reviewer

Save the events ​

With --json, the run prints one JSON event per line on stdout. The reviewer has a prompt, so the run needs no --prompt:

terminal
sh
pandra run github.com/pandra-io/pandra/examples/reviewer --json > events.jsonl

events.jsonl then holds these lines, with your own session ID, workspace, answer, usage, and skills:

text
{"type":"version","schema_version":"1.0"}
{"type":"progress","phase":"preparing"}
{"type":"session","session_id":"8a7f898cddb14a6c957e389ef713bf78","name":null,"agent":"github.com/pandra-io/pandra/examples/reviewer","package_digest":"sha256:52c8e3b2856980c2baeb2b4772ae13f1beeb79b4c9f257109468ee50563c7f6d","harness":"claude-code","workspace":"/home/you/shop","backend":"host","network":null}
{"type":"progress","phase":"starting"}
{"type":"progress","phase":"running"}
{"type":"answer","text":"src/cart.py:42 adds prices as floats; use integer cents.","data":null}
{"type":"result","session_id":"8a7f898cddb14a6c957e389ef713bf78","outcome":"completed","exit_code":0,"usage":{"input_tokens":10,"output_tokens":5,"cached_input_tokens":0,"cost_usd":0.000035},"skills":{"loaded":["ponytail-review"],"preloaded":[],"not_loaded":["pandra"],"loaded_in_run":["ponytail-review"]}}

Read the answer ​

Take the answer, the session ID, and the outcome with jq:

terminal
sh
jq -r 'select(.type == "answer") | .text' events.jsonl
jq -r 'select(.type == "session") | .session_id' events.jsonl
jq -r 'select(.type == "result") | .outcome' events.jsonl
text
src/cart.py:42 adds prices as floats; use integer cents.
8a7f898cddb14a6c957e389ef713bf78
completed

The outcome is completed, failed, or interrupted, and a file without a result event means the run ended abnormally. Keep the session ID to continue the conversation. When you need only the answer, leave out --json: a run whose stdout is not a terminal writes only the answer there.

Learn more about the event stream →

Released under the Apache License 2.0