Skip to main content
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 do
  • result_type: The expected type of the result (defaults to str)
  • tools: Optional list of functions the AI can use
  • thread: Optional thread for conversation context
  • agents: Optional list of agents to use
  • raise_on_failure: Whether to raise exceptions on failure (defaults to True)
  • 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:

Async Multiple Tasks