Functions
Run
Execute AI tasks with a single line of code
The run
function is the simplest way to execute AI tasks in Marvin. It provides a clean, one-line interface for running tasks while handling all the complexity of task creation and execution under the hood.
Motivation
While Marvin provides powerful tools for complex AI workflows, many use cases are simple and don’t need all that complexity. The run
function provides:
- A simple, intuitive interface
- Sensible defaults
- Type safety through result types
- Easy access to common parameters
Usage
Parameters
instructions
: What you want the AI to doresult_type
: The expected type of the result (defaults tostr
)tools
: Optional list of functions the AI can usethread
: Optional thread for conversation contextagents
: Optional list of agents to useraise_on_failure
: Whether to raise exceptions on failure (defaults toTrue
)handlers
: Optional list of handlers for events**kwargs
: Additional context passed to the task
Async Support
The function is also available in an async version:
Examples
Simple Text Tasks
Using Tools
Structured Output
Using Context
Multiple Tasks
The run_tasks
function allows you to run multiple tasks at once: