Mesedi Python SDK
Status: v0.2.0. Live on PyPI.
The Mesedi SDK observes autonomous AI agent runs and ships them to the Mesedi backend for failure-class detection and analysis. The v1 surface:
mesedi.configure(api_key=...): set up the module-level client@mesedi.wrap: decorate any function as an "agent execution". The SDK records start, completion (or crash), wall-clock duration, and a stable crash signature suitable for grouping identical exceptions.@mesedi.tool: decorate any function as an observed tool call. Emitstool_callevents into the surrounding execution context.- Framework adapters for LangChain, LangGraph, OpenAI Agents SDK, and CrewAI (see below).
Install
pip install mesedi
Quickstart
import mesedi
mesedi.configure(api_key="mesedi_sk_...")
@mesedi.wrap
def run_my_agent(query: str) -> str:
# ... your agent logic here ...
return "answer"
run_my_agent("hello")
For local backend development against localhost:8080, pass an explicit
base_url=. Otherwise the SDK posts to the Mesedi production backend.
What lands in the backend
For each @wrap-decorated call:
- On entry:
POST /executionswithexecution_id,status="started",sdk_language="python",sdk_version="0.2.0". - On normal return:
PATCH /executions/{id}withstatus="completed",ended_at,duration_ms. - On exception:
PATCH /executions/{id}withstatus="crashed",crash_signature(SHA-256-derived stable hash of exception type + top of traceback), then the original exception is re-raised.
Network failures during observation NEVER block the wrapped function. The SDK is fail-open: a Mesedi outage degrades to invisibility, not to broken production code.
Optional: hard-halt with local budgets
Cap a single execution across four axes — input tokens, output tokens,
wall-clock seconds, and step count. Pass any subset; unset fields impose
no limit on that axis. When any budget is exceeded, the SDK raises
MesediHalt at the next safe boundary (between LLM calls, tool calls,
or explicit checkpoint()s), never mid-call, so try/finally cleanup
runs and open resources release.
from mesedi import wrap, Budget
@wrap(budget=Budget(
max_wall_clock_seconds=600, # 10 min real time
max_steps=30, # 30 tool/LLM/checkpoint boundaries
max_tokens_in=200_000,
max_tokens_out=50_000,
))
def my_agent(query: str):
...
When a budget is supplied, the SDK also opens an SSE subscription to
GET /executions/{id}/halt-stream. Operators can halt a running
execution from the dashboard. If the SSE connection fails (backend
unreachable, 4xx/5xx, network partition), the reader logs and returns
— the wrapped agent keeps running with local budgets still enforced
client-side. Mesedi never decides to halt on its own; operator intent
or your own budget rules are the only triggers. MesediHalt inherits
from BaseException (not Exception), so broad except Exception
handlers do not swallow it.
Framework integrations
If your agent is built on LangChain, LangGraph, the OpenAI Agents SDK, or
CrewAI, you don't have to wrap every function with @mesedi.tool by hand.
Adapter modules under mesedi.integrations.* translate each framework's
native callback or hook surface into Mesedi telemetry. They're optional:
importing mesedi itself never requires any framework to be installed.
The pattern is the same across frameworks: your function gets @mesedi.wrap
for the execution boundary, and a one-line adapter does the in-execution
event emission.
LangChain
pip install mesedi[langchain]
import mesedi
from mesedi.integrations.langchain import MesediCallbackHandler
@mesedi.wrap
def run_agent(question: str) -> str:
chain = build_chain()
result = chain.invoke(
{"input": question},
config={"callbacks": [MesediCallbackHandler()]},
)
return result["output"]
The callback handler subscribes to LangChain's standard on_llm_start /
on_llm_end / on_tool_start / on_tool_end (etc.) hooks and emits
llm_call and tool_call events with the same wire format as a
hand-written mesedi.emit_llm_call() + @mesedi.tool pair. Detectors
(drift, identical/similar-call loops, tool-failures, cost-velocity,
prompt-injection) see no difference.
LangGraph
pip install mesedi[langgraph]
import mesedi
from mesedi.integrations.langgraph import instrument_graph
@mesedi.wrap
def run_my_graph(question: str) -> str:
graph = build_graph()
instrument_graph(graph)
result = graph.invoke({"input": question})
return result["output"]
instrument_graph attaches Mesedi telemetry to each node in the graph,
emits llm_call and tool_call events for the LLM-backed nodes, and
labels each event with the node name so the dashboard timeline shows the
graph's flow alongside the per-step detail.
OpenAI Agents SDK
pip install mesedi[openai-agents]
import mesedi
from mesedi.integrations.openai_agents import instrument_agent
@mesedi.wrap
def run_my_agent(question: str) -> str:
agent = build_agent()
instrument_agent(agent)
return agent.run(question)
instrument_agent subscribes to the OpenAI Agents SDK's lifecycle hooks
and emits llm_call + tool_call events with the same wire format as
the LangChain and LangGraph adapters, so detectors see no difference.
CrewAI
pip install mesedi[crewai]
import mesedi
from mesedi.integrations.crewai import instrument_crew
@mesedi.wrap
def run_my_crew(question: str) -> str:
crew = build_crew()
instrument_crew(crew)
return str(crew.kickoff(inputs={"question": question}))
instrument_crew is one line that does three things, all idempotent:
- Attaches a Mesedi
MesediCallbackHandlerto each agent's LLM. Same LLM/tool telemetry as the LangChain integration above, because CrewAI uses LangChain under the hood. - Sets
crew.step_callbackto emitcrewai.agent_action/crewai.agent_finishcheckpoint events per agent step. - Sets
crew.task_callbackto emitcrewai.task_completedcheckpoint events per finished task.
Result: the dashboard timeline shows LLM/tool detail interleaved with CrewAI's higher-level reasoning rhythm.
Releases
This SDK is published to PyPI via OIDC Trusted Publishing from the
release-sdk-python.yml GitHub Actions workflow, with no long-lived
PYPI_TOKEN secret. Every release carries the PyPI "verified" provenance
badge linking it to a specific commit in mesedi-ai/mesedi.
To cut a new release, bump version in pyproject.toml, commit, then:
git tag -a sdk-python-v0.X.Y -m "Release sdk-python v0.X.Y"
git push origin sdk-python-v0.X.Y
The workflow type-checks, builds, validates with twine, and publishes.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mesedi-0.5.1.tar.gz.
File metadata
- Download URL: mesedi-0.5.1.tar.gz
- Upload date:
- Size: 107.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
101fff764f67e8c75012e08e723c303a022f2c66c8700152c80e939cbb788e73
|
|
| MD5 |
8641aebc852ce42302496d7988a581f5
|
|
| BLAKE2b-256 |
78d7a0ac7e0b0f3a2e0a418f09d031fc0ff1d72373aa2f247fba0354e08f8133
|
Provenance
The following attestation bundles were made for mesedi-0.5.1.tar.gz:
Publisher:
release-sdk-python.yml on mesedi-ai/mesedi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesedi-0.5.1.tar.gz -
Subject digest:
101fff764f67e8c75012e08e723c303a022f2c66c8700152c80e939cbb788e73 - Sigstore transparency entry: 2538688029
- Sigstore integration time:
-
Permalink:
mesedi-ai/mesedi@cb5cc6b96506a1bb5ec496a8e8ab96ee786f478d -
Branch / Tag:
refs/tags/sdk-python-v0.5.1 - Owner: https://github.com/mesedi-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk-python.yml@cb5cc6b96506a1bb5ec496a8e8ab96ee786f478d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mesedi-0.5.1-py3-none-any.whl.
File metadata
- Download URL: mesedi-0.5.1-py3-none-any.whl
- Upload date:
- Size: 128.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
408985a16db26ff67cddb64914c8086a7ab6a8c6467d5b19b056acba8ee94cd2
|
|
| MD5 |
f7f1ff22c2d3fe5a81e298368fb2863c
|
|
| BLAKE2b-256 |
6b1faaaf450178afb708a1b537a93dca3cd55f98fd24925a86b42e924658a644
|
Provenance
The following attestation bundles were made for mesedi-0.5.1-py3-none-any.whl:
Publisher:
release-sdk-python.yml on mesedi-ai/mesedi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesedi-0.5.1-py3-none-any.whl -
Subject digest:
408985a16db26ff67cddb64914c8086a7ab6a8c6467d5b19b056acba8ee94cd2 - Sigstore transparency entry: 2538688154
- Sigstore integration time:
-
Permalink:
mesedi-ai/mesedi@cb5cc6b96506a1bb5ec496a8e8ab96ee786f478d -
Branch / Tag:
refs/tags/sdk-python-v0.5.1 - Owner: https://github.com/mesedi-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk-python.yml@cb5cc6b96506a1bb5ec496a8e8ab96ee786f478d -
Trigger Event:
push
-
Statement type: