Welcome to Marvin! This quickstart guide will walk you through the three main ways to use Marvin to create AI-powered applications.

You’ll learn how to:

  1. Use quick one-liners with marvin.run()
  2. Work with specialized agents using agent.run()
  3. Control tasks directly with task.run()
  4. Add advanced features like context and threads

This guide assumes you have already installed marvin. See the installation docs for instructions.

Quick One-Liners

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

import marvin

# Run a simple task
print(marvin.run("Write a haiku about Python programming"))

# With a specific result type
numbers = marvin.run(
    "Generate five random numbers between 1 and 10",
    result_type=list[int]
)

Specialized Agents

Create and use specialized agents for specific types of tasks:

from marvin import Agent

# Create a specialized agent
writer = Agent(
    name="Technical Writer",
    instructions="Write clear, engaging content for developers"
)

# Use the agent directly
article = writer.run(
    "Write a short article about Python type hints",
    result_type=str
)

print(article)

Task Control

For full control over your AI workflows, create and run tasks directly:

import httpx
from marvin import Task
from pydantic import BaseModel

def check_weather(location: str) -> str:
    url = f"https://wttr.in/{location}?format=%C+%t"
    return httpx.get(url).text

# Define a structured output type
class WeatherForecast(BaseModel):
    temperature: float
    conditions: str
    precipitation_chance: float | str = "unknown"

# Create a task with specific requirements
task = Task(
    instructions="Get the weather for San Francisco",
    result_type=WeatherForecast,
    tools=[check_weather]  # Custom tools
)

# Run the task
forecast = task.run()
print(forecast)

Advanced Features

All three approaches support advanced features like context, threads, and tools:

import marvin
from marvin import Agent, Task

# Context improves results
data = "The patient reports mild fever and fatigue."
diagnosis = marvin.run(
    "Suggest possible conditions",
    context={"medical_notes": data}
)

# Threads maintain conversation history
with marvin.Thread() as thread:
    # Ask multiple related questions
    marvin.run("What is quantum computing?")
    marvin.run("How does that relate to classical computing?")
    marvin.run("What are its practical applications?")

# Teams of agents can collaborate
researcher = Agent("Researcher")
writer = Agent("Technical Writer")
editor = Agent("Editor")

with marvin.Thread() as thread:
    research = researcher.run("Research quantum computing")
    draft = writer.run("Write an article", context={"research": research})
    final = editor.run("Edit the article", context={"draft": draft})

What’s Next?

You’ve seen the main ways to work with Marvin. To learn more:

  • Read about Tasks to understand how to structure AI workflows
  • Learn about Agents to create specialized AI workers
  • Explore Threads for managing conversation context
  • Check out Models to work with structured data