Real-World Projects
Larger end-to-end examples: automobile spec, data harmonization, HTML email builder, financial planner with MCP.
#Real-World Projects
Longer end-to-end examples that show the SDK at the scale of an actual feature. Each one is a runnable module in the maivn-examples catalog, with a check at the end that fails the run if the answer is wrong. The code below is condensed. Open the module for the full version, and see the examples index for how to install and run the catalog.
These are more "study these" than "copy these". They show patterns that are awkward to demonstrate in a single-page example.
#Customer data harmonization
Module: examples.analysis.data_harmonization.demo
What it shows: a deterministic local tool does the exact work, and the model explains the result in a typed answer.
Input is a small CSV export with padded names, mixed-case emails and regions, a duplicate address and a malformed address. The clean_export function trims whitespace, lowercases emails, uppercases regions, drops duplicates by email and rejects malformed emails. The model never touches the rows itself:
from maivn import Agent
from pydantic import BaseModel
class Contact(BaseModel):
name: str
email: str
region: str
class ImportReport(BaseModel):
contacts: list[Contact]
duplicate_rows: int
rejected_rows: int
explanation: str
def clean_export() -> dict:
"""Normalize case and whitespace; deduplicate by email and reject bad emails."""
...
assistant = Agent(
name='Customer Import Assistant',
system_prompt=(
'Use clean_export to inspect the supplied customer CSV. Return its cleaned records and '
'counts exactly, and explain the normalization, duplicates, and rejected rows.'
),
api_key='...',
)
assistant.add_tool(clean_export)
assistant.add_tool(ImportReport, final_tool=True)The run is checked against the same function. Expect two contacts, one duplicate row and one rejected row.
Best for: import and ETL steps where the model handles the explanation and your code owns the precision-critical step.
#Delivery vehicle specification
Module: examples.documents.vehicle_spec_builder.demo
What it shows: nested Pydantic models as the answer, with explicit arithmetic checked afterwards.
A delivery_requirements tool returns fixed customer requirements. The final tool is a VehicleSpecification with a nested Battery and Cargo:
from pydantic import BaseModel, Field
class Battery(BaseModel):
capacity_kwh: float = Field(gt=0)
usable_fraction: float = Field(gt=0, le=1)
consumption_kwh_per_km: float = Field(gt=0)
class Cargo(BaseModel):
payload_kg: float = Field(gt=0)
volume_m3: float = Field(gt=0)
doors: list[str]
class VehicleSpecification(BaseModel):
name: str
route_km: float = Field(gt=0)
seats: int = Field(ge=1)
battery: Battery
cargo: Cargo
unverified_checks: list[str] = Field(min_length=3)After the run, the example checks that the specification keeps the supplied payload, route and energy assumptions and that the usable battery energy covers the route with 20 percent headroom. It also requires braking, crashworthiness and loaded-range testing to be listed as unverified. The output is a conceptual specification, not a vehicle certification.
Best for: product specification, configuration generation and structured report assembly.
#Project report builder
Module: examples.documents.report_builder.demo
What it shows: one model draft rendered to four file formats locally.
The agent reads a synthetic project snapshot with a project_facts tool and fills a ProjectReport. Public maivn_tools builders (DocumentsToolSet, PDFToolSet, PresentationsToolSet and WorkbooksToolSet) then write Word, PDF, PowerPoint and Excel files on your machine. Nothing is uploaded or shared. This one needs the maivn-tools package as well as the SDK.
Best for: reports where the facts are fixed and the writing is the model's job.
#Investment memo (MCP swarm)
Module: examples.analysis.investment_memo.demo
What it shows: a swarm of two analysts and a planner, with MCP servers for live data and a validator on the final answer.
┌──────────────────┐ ┌───────────────────┐
│ Crypto Analyst │ │ Currency Analyst │
│ (MCP: coingecko) │ │ (MCP: frankfurter)│
└────────┬─────────┘ └─────────┬─────────┘
└───────────┬───────────┘
▼
┌──────────────────────────┐
│ Investment Planner │
│ (use_as_final_output) │
└──────────────────────────┘Both analysts use the same generic fetch server, which the SDK launches through uvx. Each server gets its own URL as a per-tool default, so the model never writes a URL:
from maivn import Agent, MCPAutoSetup, MCPServer, Swarm
fetcher = MCPAutoSetup(
provider='uvx',
package='mcp-server-fetch',
with_packages=['mcp<2'],
args=['--ignore-robots-txt'],
env={'PYTHONIOENCODING': 'utf-8'},
)
def market_source(name: str, url: str) -> MCPServer:
"""An MCP server whose fetch tool defaults to one API URL."""
return MCPServer(
name=name,
transport='stdio',
auto_setup=fetcher,
stdio_response_timeout_seconds=30.0,
default_tool_args={'raw': True, 'max_length': 2000},
tool_defaults={'fetch': {'url': url}},
)
CRYPTO_URL = 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd'
RATES_URL = 'https://api.frankfurter.app/latest?from=USD&to=EUR,GBP,JPY'
crypto_analyst = Agent(name='Crypto Analyst', api_key='...')
crypto_analyst.register_mcp_servers(market_source('coingecko', CRYPTO_URL))
currency_analyst = Agent(name='Currency Analyst', api_key='...')
currency_analyst.register_mcp_servers(market_source('frankfurter', RATES_URL))
planner = Agent(name='Investment Planner', api_key='...', use_as_final_output=True)
desk = Swarm(
name='Investment Desk',
agents=[crypto_analyst, currency_analyst, planner],
)The planner's final tool is an InvestmentMemo model whose allocation field has a validator. A memo that allocates 90 percent of the money is rejected instead of delivered:
import math
from pydantic import BaseModel, field_validator
class InvestmentMemo(BaseModel):
allocation: dict[str, int]
@field_validator('allocation')
@classmethod
def whole_portfolio(cls, allocation: dict[str, int]) -> dict[str, int]:
total = math.fsum(allocation.values())
if not math.isclose(total, 100, abs_tol=0.001):
raise ValueError(f'allocation percentages must total 100, got {total:g}')
return allocationThe first run installs the fetch server, so it starts slower than later runs. The module calls close() on each agent in a finally block, which stops the MCP servers registered on that agent. See MCP Integration.
Best for: swarms where each member needs a distinct external data source and a single coordinator merges the results.
#Patterns that show up across these projects
A few patterns repeat. They are worth internalizing:
- Make the schema do the work. When the final answer is structured, write the Pydantic model first, then let the agent figure out how to fill it in. Add validators for rules the model must not break.
- Separate interpretation from precision. The model is good at "understand what the user means" and "explain what happened". Function tools are good at "trim, dedupe and format exactly". Combine them instead of forcing one to do the other's job.
- Keep fixed inputs out of the prompt. Endpoints belong in MCP
tool_defaults, and credentials belong inagent.private_datainjected with@depends_on_private_data. Never inline them in system prompts.
- Use swarms for role separation, not task decomposition. A swarm is useful when each member has a distinctly different role (analyst, reviewer, director). For "do this big thing in parallel," a single agent with deep dependencies is usually simpler.
#What's next
- Basics — the patterns above, in their simplest form.
- Swarms — the multi-agent building blocks behind the investment memo.
- MCP Integration — registering MCP servers like the ones in the memo.
- Memory — for projects where the agent needs to remember context across invocations.