swadhinbiswas WIP save-point: production hardening, H3 removal, fmt gate, and accumulated phase work · 7/15/2026
a293d8c
36 lines · 1.6 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

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