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_KEYMOONDREAM_API_KEYLOGFIRE_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:
textevidenceiterationsinput_tokens,output_tokens,cost_usdwall_time_s
Development (repo)
If you are working from the repository:
just dev— API + UIjust 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.
Metadata
Release files for sanjaya 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sanjaya-0.2.1.tar.gz | 96.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sanjaya-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 196.2 kB
Release files / sanjaya-0.2.1.tar.gz
| Download URL | sanjaya-0.2.1.tar.gz |
|---|---|
| Size | 96.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68ca6557f988f66d6208fe0984f7cca5e41dc2a285d6935ae65bb99501a94dd0
|
|
BLAKE2b-256 checksum How to use checksums |
ad6402c7195f91ad06d6134dfc5c081af7b60bde3c5bf473e197d4ff87de43ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / sanjaya-0.2.1-py3-none-any.whl
| Download URL | sanjaya-0.2.1-py3-none-any.whl |
|---|---|
| Size | 99.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46525eea000dee41f16e4540fe90d0be95ae60515e50b53d74eb1a8ee3c7e290
|
|
BLAKE2b-256 checksum How to use checksums |
a7b712321502422d33f75e6cf0d0f072fc16160f500335b5c3fb7c5ccf9063f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|