Overview
Choose a starting point and understand what runs locally and what the service handles.
#mAIvn SDK Overview
mAIvn lets you build AI agents that reliably use your own code as tools, coordinate as teams, and keep secrets out of the model.
This overview explains what mAIvn is, how the SDK works, how to install it, and where to go next.
#What mAIvn Is
mAIvn is a Python SDK for building agents: programs that can reason about a request and then take action by calling tools.
Three ideas carry the whole SDK:
- Agents. An
Agentis the thing you talk to. You give it a name, a system prompt, and a set of tools, and it decides which tools to call to fulfill a request. - Tools are your own functions. A tool is just a Python function (or a Pydantic model) that you mark with
@agent.toolify(). The agent can call it, but the code is yours: your business logic, your API calls, your database access. - Teams of agents. When one agent isn't enough, a
Swarmcoordinates several specialized agents so they can hand work back and forth.
If you can write a Python function, you can give an agent a new capability.
#Why It Matters
The defining property of mAIvn is where your code runs.
When you register a tool, the agent does not receive your code. Your tool's code never leaves your environment: the platform receives each tool's name, its description and the types of its parameters, and the function body stays on your machine and runs there.
The data a run needs does go to the platform, and on to the model provider that serves the run: your messages and files, and the arguments and results of tool calls. Values you mark as private are replaced with placeholders before a model sees them. See the Private Data Guide.
Note: Your tool code executes locally in your environment. It is never transferred to or executed on mAIvn servers. The platform receives each tool's name, description and parameter types for orchestration, and the run's data as described above.
That one design choice gives you:
- Private business logic. Your implementation never leaves your environment.
- Local data access. Tools can read your database, hit internal services, or touch the filesystem. You decide what each tool returns, and only what it returns goes back to the run.
- Secrets out of the model. Sensitive values such as API keys, passwords and PII can be declared as private data and injected into your tools only at execution time. The model plans against the names of those values, never the values themselves, and known private values in tool results are redacted before they return to the model. See the Private Data Guide.
You get the planning ability of a hosted orchestrator without surrendering your code or your secrets to it.
#How It Works at a Glance
The flow: you describe tools and rules; the hosted orchestrator plans; your code runs locally; a typed response comes back.
Concretely, every invocation flows through four conceptual stages:
- You author scopes. A scope is an
Agentor aSwarm. You declare its tools, the rules between them (dependencies, private data, structured output), and any configuration. - The hosted orchestrator plans. When you call
invoke(), the SDK sends your message and the schemas of your tools to the orchestrator, which decides what to do and in what order. - Your tools execute locally. When the plan calls a tool, the SDK runs your function in your own process and sends only the result back. Private values are injected at this moment and redacted from results.
- A typed response comes back. You receive an
InvokeResponse. Readresponse.responsefor the final assistant text, orresponse.resultfor structured output.
You stay in control of the code and the data, and the orchestrator handles the reasoning about which tool to call and when.
#Install
pip install maivnOr with uv:
uv add maivnmAIvn requires Python 3.10 or newer. It depends on the public maivn-contracts package and installs it automatically. Check the installed release with maivn version.
Optional extras add features you may not need:
The SDK also installs private-data-vault. On a supported desktop with an available OS credential store, it opens encrypted local storage when caller private values are first used. Installation itself does not create a vault. Servers need a durable directory and a secret-manager key. See Values that outlive one call for setup and recovery, and for how local deletion works.
#Your First Agent
A short script defines an agent, gives it a tool, and runs it:
import os
from maivn import Agent
from maivn.messages import HumanMessage
agent = Agent(name='assistant', api_key=os.environ['MAIVN_API_KEY'])
@agent.toolify(description='Get current weather for a city')
def get_weather(city: str) -> dict:
return {'city': city, 'temp': 72, 'condition': 'sunny'}
response = agent.invoke([HumanMessage(content='What is the weather in Austin?')])
print(response.response)Agent accepts an explicit api_key, a preconfigured Client, or credentials from the process environment or an explicitly selected credential file. This example reads the environment itself. See Authentication.
For a guided, step-by-step build of this same agent (including structured output and live event streaming), start with the Getting Started guide.
#Where to Go Next
Pick the path that matches what you're trying to do.
Start here
- Getting Started: build your first agent step by step, return a typed answer, and watch execution events.
- Core Concepts: scopes, tools, swarms, dependencies, sessions and structured output on one page.
- Best Practices: patterns for tools, prompts, privacy, errors and swarms before you go to production.
- Glossary: short definitions for the terms that are easy to confuse.
- Troubleshooting: error messages, their causes and fixes.
- Versioning, Upgrading to SDK 2.0 and Upgrading to SDK 3.0: version numbers, the stable import surface, what changed from 0.x, and what 3.0 removed.
Build agents
- Tools and Dependencies: define tools as functions or Pydantic models, then chain them.
- Structured Output: typed responses on
response.result. - Decisions: categorical answers, safe fallbacks and optional invocation gates.
- Multi-Agent: coordinate specialized agents with a
Swarm. - Private Data: keep secrets and PII out of the model.
- Hosted Jobs: bounded runs that continue after your client disconnects. Disabled by default and available from SDK 2.3.0.
- MCP, System Tools, Memory and Recall and SDK Resource Configuration: connect servers, use built-in tools, carry context and attach resources.
- Interrupts: pause a run for human input.
- Sessions and Streaming and Frontend Events: stream progress to a UI.
- Scheduled Invocation: run an agent on a schedule.
- Reliability: timeouts and retries.
- Testing: offline tests for tools and agents.
Start agents from events
- Email triggers: start when mail arrives.
- Form triggers: start from a form submission.
- GitHub triggers: react to pull requests, issues and pushes.
- Stripe triggers: react to events from your own Stripe account.
- Discord triggers: start from Discord.
- Database triggers: start when a row in your Postgres or Supabase database changes.
- Local file triggers: start when a local file arrives or changes.
- Local webhook tunnel: test incoming webhooks from your machine.
Account, Portal and Studio
- Authentication and API Keys and Webhooks: credentials and key management.
- Billing and Usage, Workspace Operations, Portal Authentication and Portal Memory Management.
- mAIvn Studio and Studio Authoring and Debugging: a local workbench for your agents.
Reference and examples
- SDK Reference: per-class documentation for
Agent,Swarm,Client, decorators, configuration, errors, events, decisions and artifacts. - Examples: a working tour of the SDK organized by what you want to build, including basics, agents and tools, swarms, decisions, private data and real-world projects.
- More example pages: batch and scheduling, interrupts, MCP and memory.