swadhinbiswas πŸš€ release: 2.0.8 β€” write-path fix (ADR-080), fork-safe GIL pool (ADR-081), HTTP/3 (ADR-082), Security DI fix, docs honesty pass Β· 8/6/2026
731fffe
45 lines Β· 1.8 KB
Raw Download

Agent-native demo

A single, runnable example that exercises justapi's three agent-native
differentiators β€” all owned by the Rust runtime, not Python:

  1. Native MCP tools β€” add, multiply, search_docs are registered with
    @app.tool. Their JSON schemas are inferred from type hints and stored in
    Rust. They are listed at GET /_system/tools and callable via
    POST /_system/tools/call (MCP shape) or the bundled app.run_mcp_stdio()
    stdio server.
  2. Durable agent session state β€” app.enable_sessions() turns on the
    Rust-backed session store. Declare session: Session on any handler to get
    per-client state with no plumbing: the id is read from the
    justapi_session cookie or ?session= query param, and a known-but-new id
    is materialized automatically so state survives across requests.
  3. Streaming validated output β€” @app.stream_json streams 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

One command β€” starts the server, runs the full demo (tools list, tool call,
streaming agent run, session state, session persistence), and stops:

bash examples/agent_demo/run_demo.sh

Manually, step by step:

# 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().