Agent-native demo
A single, runnable example that exercises justapi's three agent-native
differentiators — all owned by the Rust runtime, not Python:
- Native MCP tools —
add,multiply,search_docsare registered with@app.tool. Their JSON schemas are inferred from type hints and stored in
Rust. They are listed atGET /_system/toolsand callable viaPOST /_system/tools/call(MCP shape) or the bundledapp.run_mcp_stdio()
stdio server. - Durable agent session state —
app.enable_sessions()turns on the
Rust-backed session store. Declaresession: Sessionon any handler to get
per-client state with no plumbing: the id is read from thejustapi_sessioncookie or?session=query param, and a known-but-new id
is materialized automatically so state survives across requests. - Streaming validated output —
@app.stream_jsonstreams a generator of
Python objects as NDJSON, validating every item against a JSON Schema in
Rust before it is written to the socket. Invalid items abort the stream.
Run
# from the repo root
uv run examples/agent_demo/app.py
# or: python examples/agent_demo/app.py
curl -N 'http://127.0.0.1:8000/agent/run?session=demo&query=streaming'
curl 'http://127.0.0.1:8000/agent/state?session=demo'
curl 'http://127.0.0.1:8000/_system/tools'
curl -X POST 'http://127.0.0.1:8000/_system/tools/call' \
-H 'content-type: application/json' \
-d '{"name":"add","arguments":{"a":5,"b":7}}'
The same app object also serves an MCP stdio server via app.run_mcp_stdio().