Skip to main content
Tasks represent discrete units of work that need to be completed by AI agents. Marvin provides several ways to execute tasks and retrieve their results.

Creating and Running Tasks

The most convenient way to run a task is with the marvin.run() function. This function creates and runs a task in a single call, accepting all the same arguments as the Task constructor:

Running a Single Task

You can also create a task first and run it later using the run() method:

Running Multiple Tasks

To run multiple tasks at once, use the run_tasks() function:

Task Dependencies

Tasks can depend on other tasks, ensuring they run in the correct order:
When you run a task, Marvin will:
  1. Check if there are any dependencies
  2. Run any incomplete dependencies first
  3. Execute the task itself
  4. Return the result

Task Results

Tasks can specify their expected result type using the result_type parameter:

Task Status

You can check a task’s status at any time:
Tasks have several helper methods for checking their status:
  • is_pending(): Task hasn’t started
  • is_running(): Task is currently executing
  • is_successful(): Task completed successfully
  • is_failed(): Task failed to complete
  • is_skipped(): Task was skipped
  • is_complete(): Task is done (successful, failed, or skipped)
  • is_incomplete(): Task isn’t done (pending or running)
  • is_ready(): Task can be run (dependencies are complete)

Task Context

Tasks maintain their own context, which can include:
  • Instructions: What needs to be done
  • Context: Additional information needed for the task
  • Tools: Functions the agent can use
  • Memories: Persistent information from previous runs
  • Result type: Expected format of the output
This context helps agents understand and complete the task effectively: