What is Marvin?

Marvin is a Python framework for building AI applications with LLMs.

Marvin provides a clean, intuitive interface for working with large language models (LLMs) while handling all the complexity of state management, conversation history, and agent coordination.

Quick Examples

Using uv? Run the examples below by copying them to your clipboard and executing:

pbpaste | uv run --with marvin -  

Simple Tasks

The fastest way to use Marvin is with marvin.run():

import marvin

print(marvin.run("Write a haiku about artificial intelligence"))

Specialized Agents

Create agents with specific skills and personalities:

import marvin

# Create specialized agents
poet = marvin.Agent(
    name="Poet",
    instructions="You are an expert poet who writes in various styles."
)

scientist = marvin.Agent(
    name="Scientist",
    instructions="You are a scientist who explains complex topics clearly."
)

# Use them for specific tasks
explanation = marvin.run(
    "Explain entropy briefly",
    agents=[scientist]
)

poem = marvin.run(
    "Write a haiku about entropy",
    agents=[poet],
    context={"scientific_background": explanation}
)

print(poem)

Structured Data

Get results in exactly the format you need:

from typing import Annotated, Literal
import marvin
from pydantic import BaseModel, Field

class Character(BaseModel):
    name: str
    role: Literal["hero", "villain", "sidekick"]
    aura: Annotated[float, Field(ge=0, le=1)]

# Get structured results
characters = marvin.run(
    "Create three characters for a mystery story",
    result_type=list[Character]
)

for char in characters:
    print(f"{char.name} - {char.role} - {char.aura}")

Persistent Memory

Give your agents memory that persists across conversations:

import marvin

# Create a memory module
preferences = marvin.Memory(
    key="user_preferences",
    instructions="Remember user preferences and style"
)

# Create an agent with memory
assistant = marvin.Agent(memories=[preferences])

# The agent will remember information across conversations
marvin.run(
    "Learn about the user's writing style preferences",
    agents=[assistant],
    cli=True
)

Why Marvin?

  • 🎯 Simple Interface: Start with one line of code, scale to complex applications
  • 🧠 Smart Defaults: Sensible defaults that just work, with customization when you need it
  • 🔄 State Management: Built-in conversation history and memory management
  • 📝 Structured Data: Get results in exactly the format you need
  • 🤝 Multi-Agent: Create specialized agents that work together
  • 🔌 Extensible: Easy to integrate with your existing Python code

Next Steps