The fastest way to use Marvin is with marvin.run():
Copy
Ask AI
import marvin# Run a simple taskprint(marvin.run("Write a haiku about Python programming"))# With a specific result typenumbers = marvin.run( "Generate five random numbers between 1 and 10", result_type=list[int])
Create and use specialized agents for specific types of tasks:
Copy
Ask AI
from marvin import Agent# Create a specialized agentwriter = Agent( name="Technical Writer", instructions="Write clear, engaging content for developers")# Use the agent directlyarticle = writer.run( "Write a short article about Python type hints", result_type=str)print(article)
Copy
Ask AI
Type Hints in Python: A Clear Path to Better CodePython's type hints bring clarity and safety to your code without sacrificing its dynamic nature. Introduced in Python 3.5, type hints allow developers to explicitly declare variable and function types, making code more maintainable and easier to understand.Here's a quick example:def greet(name: str) -> str: return f"Hello, {name}!"Type hints help catch errors early, improve IDE support, and make your code self-documenting. While optional, they're becoming an essential tool in modern Python development.
All three approaches support advanced features like context, threads, and tools:
Copy
Ask AI
import marvinfrom marvin import Agent, Task# Context improves resultsdata = "The patient reports mild fever and fatigue."diagnosis = marvin.run( "Suggest possible conditions", context={"medical_notes": data})# Threads maintain conversation historywith 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 collaborateresearcher = 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})