Files
OpenJarvis/docs/getting-started/snippets.md
T
Jon Saad-FalconandClaude Opus 4.6 880e3f67f2 feat: feature gap closure — streaming SDK, parallel tools, structured output, Docker sandbox, session checkpoints, 5 hero demos
Closes the remaining feature gaps vs Qwen-Agent, CoPaw, Google ADK, Apple FM SDK, and LFM2:

SDK:
- Add ask_stream() and ask_full_stream() async generator methods to Jarvis class

Orchestrator:
- Parallel tool execution via ThreadPoolExecutor (parallel_tools=True by default)

Engine:
- ResponseFormat dataclass for structured output / JSON mode
- OpenAI, Anthropic, Google, and Ollama structured output support

Tools:
- DockerCodeInterpreterTool (code_interpreter_docker) with sandboxed execution
- sandbox-docker optional dependency

Rust:
- Session checkpointing with checkpoint(), rewind(), list_checkpoints()

Examples (5 hero demo apps):
- browser_assistant — web browsing agent
- security_scanner — project security auditor
- daily_digest — morning news briefing
- doc_qa — document Q&A with memory indexing
- multi_model_router — cost-optimized model routing

Docs:
- 10 copy-paste code snippets page
- "What You Can Build" quickstart section

Tests: 275 Python tests pass, 392 Rust tests pass, lint clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 04:47:24 +00:00

3.1 KiB

title, description
title description
Code Snippets Copy-paste patterns for common OpenJarvis tasks

Code Snippets

Ready-to-use patterns for the most common OpenJarvis tasks. Each snippet is self-contained and copy-pasteable.

Ask a Question (3 lines)

from openjarvis import Jarvis

with Jarvis() as j:
    print(j.ask("What is the capital of France?"))

Stream Tokens (4 lines)

import asyncio
from openjarvis import Jarvis

async def main():
    with Jarvis() as j:
        async for token in j.ask_stream("Tell me a story"):
            print(token, end="", flush=True)

asyncio.run(main())

Agent with Tools (5 lines)

from openjarvis import Jarvis

with Jarvis() as j:
    result = j.ask_full(
        "Search the web for the latest Python release",
        agent="orchestrator",
        tools=["web_search", "think"],
    )
    print(result["content"])

Memory: Index + Search (6 lines)

from openjarvis import Jarvis

with Jarvis() as j:
    j.memory.index("./docs/", chunk_size=512)
    results = j.memory.search("deployment options")
    for r in results:
        print(f"[{r['score']:.3f}] {r['content'][:100]}")

Recipe TOML (4 lines)

Define an agent pipeline in TOML — no code required:

[recipe]
name = "research_assistant"
agent = "orchestrator"
tools = ["web_search", "think", "file_read"]
prompt = "Research the given topic and write a summary."

Run with: jarvis compose run research_assistant "quantum computing advances"

API Server (1 command)

jarvis serve --port 8000 --engine ollama --model qwen3:8b

Any OpenAI-compatible client works against this endpoint.

Docker Deployment (2 commands)

docker build -t openjarvis .
docker run -p 8000:8000 openjarvis serve --host 0.0.0.0

Custom Tool (10 lines)

from openjarvis.core.registry import ToolRegistry
from openjarvis.core.types import ToolResult
from openjarvis.tools._stubs import BaseTool, ToolSpec

@ToolRegistry.register("my_tool")
class MyTool(BaseTool):
    tool_id = "my_tool"

    @property
    def spec(self):
        return ToolSpec(name="my_tool", description="My custom tool",
                        parameters={"type": "object", "properties": {"input": {"type": "string"}}})

    def execute(self, **params):
        return ToolResult(tool_name="my_tool", content=f"Processed: {params.get('input', '')}", success=True)

Multi-Model Routing (5 lines)

from openjarvis import Jarvis

j = Jarvis()
# Router automatically selects the best model per query
simple = j.ask("What is 2+2?")            # routes to fast/cheap model
complex = j.ask("Analyze this research paper...")  # routes to capable model
j.close()

Human-in-the-Loop Confirmation (6 lines)

from openjarvis import Jarvis

with Jarvis() as j:
    result = j.ask_full(
        "Delete old log files in /tmp",
        agent="orchestrator",
        tools=["shell_exec", "file_read"],
    )
    print(f"Agent took {result['turns']} turns")
    print(result["content"])

Tools like shell_exec can be configured with requires_confirmation: true in TOML for interactive approval.