Skip to content

Repository files navigation

Pisama

Find and fix failures in AI agent systems. No LLM calls required.

PyPILicense: MITPython 3.10+

Pisama ships heuristic detectors that apply across frameworks including n8n, LangGraph, Dify and OpenClaw, with per-platform gating (for example coordination runs only on multi-agent platforms). They run locally with zero LLM cost on the heuristic tier.

Install

pip install pisama

Usage

frompisamaimportanalyzeresult=analyze("trace.json") # also accepts dicts and JSON stringsforissueinresult.issues:
print(f"[{issue.type}] {issue.summary} (severity: {issue.severity})")
print(f" Fix: {issue.recommendation}")

CLI

pisama analyze trace.json # Analyze a trace
pisama watch python my_agent.py # Watch a live agent (pip install "pisama[auto]")
pisama replay <trace-id># Re-run detection on stored traces
pisama smoke-test --last 50 # Batch test recent traces
pisama detectors # List all core detectors
pisama mcp-server # Start MCP server (pip install pisama[mcp])

MCP Server

Works in Cursor, Claude Desktop, and Windsurf. No API key is needed:

{
"mcpServers": {
"pisama": { "command": "pisama", "args": ["mcp-server"] }
}
}

Optional extras

The base pisama install has zero-cost heuristic detection covered. Two extras add opt-in functionality on top.

Auto-instrumentation: pisama[auto]

Zero-code tracing for LLM calls. init() patches supported clients (Anthropic, OpenAI) so every call after it emits an OTEL trace Pisama can analyze, no manual instrumentation needed.

pip install "pisama[auto]"
importpisama.autopisama.auto.init(api_key="ps_...")
# All subsequent LLM calls are automatically tracedimportanthropicclient=anthropic.Anthropic()
response=client.messages.create(...) # traced automatically

This used to require the standalone pisama-auto package. That package still works and stays fully supported for existing installs; pisama[auto] is the same code, folded into the base package so there is one less dependency to track. New projects should install it this way.

Agent hooks and tools: pisama[agents]

Real-time hooks, tools, and self-check utilities for agent runtimes (built for the Claude Agent SDK), wired to Pisama's detection infrastructure for in-loop failure prevention rather than after-the-fact analysis.

pip install "pisama[agents]"
frompisama.agentsimportpre_tool_use_hook, post_tool_use_hookagent.hooks.pre_tool_use=pre_tool_use_hookagent.hooks.post_tool_use=post_tool_use_hook

Active self-check is available the same way:

frompisama.agentsimportcheckresult=awaitcheck(
output="The server is healthy based on the metrics.",
context={"query": "Is auth-service down?", "sources": [...]},
)
ifnotresult["passed"]:
... # revise output based on result["issues"]

This used to require the standalone pisama-agent-sdk package. That package still works and stays fully supported for existing installs; pisama[agents] is the recommended path for new projects, one package instead of two.

Detectors

Core detectors, gated per platform (n8n, LangGraph, Dify, OpenClaw and others). A representative selection:

DetectorWhat It Catches
loopInfinite loops, retry storms, stuck patterns
coordinationDeadlocked handoffs, message storms
hallucinationFactual errors, fabricated tool results
injectionPrompt injection, jailbreak attempts
corruptionState corruption, type drift
persona_driftPersona drift, role confusion
derailmentTask deviation, goal drift
contextContext neglect, ignored instructions
specificationOutput vs. requirement mismatch
communicationInter-agent message breakdown
decompositionPoor task breakdown, circular dependencies
workflowUnreachable nodes, missing error handling
completionPremature completion, unfinished work
withholdingSuppressed findings, hidden errors
convergenceMetric plateau, regression, thrashing
overflowContext window exhaustion
propagationSilent error propagation across steps
citationFabricated citations and source misattribution
routingInputs misrouted to the wrong specialist agent
mcp_protocolMCP tool-communication failures

Links

License

MIT

Source boundary

This repository is the public source for the MIT-licensed pisama Python package. It does not contain the Pisama Cloud backend, dashboard, calibration data, managed detection tiers, or paid automation.

About

Public source for the MIT-licensed pisama Python CLI, SDK, and MCP server

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages