Running Tasks
Execute tasks and manage their results.
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:
- Check if there are any dependencies
- Run any incomplete dependencies first
- Execute the task itself
- 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 startedis_running()
: Task is currently executingis_successful()
: Task completed successfullyis_failed()
: Task failed to completeis_skipped()
: Task was skippedis_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: