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.1.tar.gz (96.7 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.1-py3-none-any.whl (99.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanjaya-0.2.1.tar.gz
  • Upload date:
  • Size: 96.7 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.1.tar.gz
Algorithm Hash digest
SHA256 68ca6557f988f66d6208fe0984f7cca5e41dc2a285d6935ae65bb99501a94dd0
MD5 5b2ee1f852fd2d27d2f7f42f4d3503f3
BLAKE2b-256 ad6402c7195f91ad06d6134dfc5c081af7b60bde3c5bf473e197d4ff87de43ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanjaya-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 99.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46525eea000dee41f16e4540fe90d0be95ae60515e50b53d74eb1a8ee3c7e290
MD5 58ec0438fa9113615015b0e33b024d84
BLAKE2b-256 a7b712321502422d33f75e6cf0d0f072fc16160f500335b5c3fb7c5ccf9063f8

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