Skip to main content

Extensible RLM agent framework with video understanding

Project description

Sanjaya

Sanjaya is a Python library for building evidence-first RLM (Recursive Language Model) agents.

It runs a loop where the model writes Python, executes it in a sandboxed REPL, inspects results, calls tools, and iterates until it can return a grounded answer.

Why the name?

In the Mahabharata, Sanjaya narrates events to a blind king with "divine sight." This project follows the same idea: observe evidence and report what happened.

Install

pip install sanjaya

With extras:

pip install "sanjaya[video]"      # video analysis
pip install "sanjaya[image]"      # image analysis (Pillow, HEIC, SVG)
pip install "sanjaya[document]"   # PDF/EPUB/PPTX/Markdown/text parsing
pip install "sanjaya[tracing]"    # tracing integrations
pip install "sanjaya[all]"        # everything

Configuration

Set at least:

  • OPENROUTER_API_KEY

Optional (depends on your model/provider setup):

  • OPENAI_API_KEY
  • MOONDREAM_API_KEY
  • LOGFIRE_TOKEN

Quick start

from sanjaya import Agent

agent = Agent(max_iterations=8)

answer = agent.ask("What is the capital of France?")
print(answer.text)

Video analysis

from sanjaya import Agent

agent = Agent(max_iterations=12)

answer = agent.ask(
    "How many people are speaking and what are they discussing?",
    video="/path/to/video.mp4",
    # subtitle="/path/to/subtitle.json",  # optional
)

print(answer.text)
print(answer.evidence)

When video=... is provided, VideoToolkit is auto-registered if you have not already added one.

Document analysis

from sanjaya import Agent

agent = Agent(max_iterations=12)

answer = agent.ask(
    "Summarize the key claims and supporting evidence.",
    document=["/path/to/report.pdf", "/path/to/appendix.md"],
)

print(answer.text)
print(answer.evidence)

Supported document types include .pdf, .epub, .pptx/.ppt, .md, and .txt.

When document=... is provided, DocumentToolkit is auto-registered if needed.

Image analysis

from sanjaya import Agent

agent = Agent(max_iterations=10)

answer = agent.ask(
    "What text is visible in this screenshot?",
    image="/path/to/screenshot.png",
)

print(answer.text)
print(answer.evidence)

Multiple images:

answer = agent.ask(
    "Compare these two charts and summarize differences.",
    image=["/path/to/chart_q1.png", "/path/to/chart_q2.png"],
)

Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP, HEIC (requires sanjaya[image]), SVG (requires sanjaya[image]).

When image=... is provided, ImageToolkit is auto-registered if needed.

Custom tools

from sanjaya import Agent, Toolkit, tool

class MyToolkit(Toolkit):
    @tool
    def lookup(self, query: str) -> str:
        return f"result for: {query}"

agent = Agent().use(MyToolkit())
answer = agent.ask("Find the latest status update")
print(answer.text)

Answer object

Agent.ask() returns an Answer object with:

  • text
  • evidence
  • iterations
  • input_tokens, output_tokens, cost_usd
  • wall_time_s

Development (repo)

If you are working from the repository:

  • just dev — API + UI
  • just api — FastAPI backend (:8000)
  • just ui — Next.js frontend (:5100)
  • just demo — run demo prompts

Status

Sanjaya is actively developed. Core video + document flows are working, and evaluation/dashboard tooling is still evolving.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanjaya-0.2.0.tar.gz (96.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sanjaya-0.2.0-py3-none-any.whl (107.6 kB view details)

Uploaded Python 3

File details

Details for the file sanjaya-0.2.0.tar.gz.

File metadata

  • Download URL: sanjaya-0.2.0.tar.gz
  • Upload date:
  • Size: 96.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sanjaya-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3d4d4a9bacd6758fc68916fbf5010d642be984b9dc86a83a800adbdda4552058
MD5 f78d78ba49c9c82a279cf7296cbbe987
BLAKE2b-256 20dc8d4801e4e7d45be4184e2723cb5c66c014aebd6953402288ca5395defd62

See more details on using hashes here.

File details

Details for the file sanjaya-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sanjaya-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 107.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sanjaya-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7602b0022cd70ee9fc6d1a9b8f55dbb13496f2375c24b1d63e268afd6470543
MD5 f5c0d329caec9234d909d0b026c435f8
BLAKE2b-256 52a8fb15d02b4ef86b669bc6ab3659bbf8b63e6aca52b881fc4fb3c0c7e6ab04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page