Agents are the intelligent, autonomous entities that power your AI workflows in Marvin. They represent AI models capable of understanding instructions, making decisions, and completing tasks.
Agents in Marvin are configurable AI entities, each with its own identity, capabilities, and even personality. They act as the “workers” in your AI workflows, responsible for executing tasks and making decisions based on their assigned instructions and available tools.You can think of each agent as a portable LLM configuration. When you assign an agent to a task, they will work to complete it according to the instructions and tools you provide.
A more complex agent can be created by providing additional configuration. This example shows the main configuration options:
Copy
Ask AI
import marvinagent = marvin.Agent( name="Data Analyst", description="An AI agent specialized in data analysis", instructions="Perform data analysis tasks efficiently and accurately.", tools=[analyze_data, plot_results], model="openai:gpt-4o", memories=[knowledge_base],)
An agent’s name is an identifier that is visible to other agents in the workflow. It is used to distinguish between agents and for logging and debugging purposes. If no name is provided, one will be randomly chosen from a list of famous AI characters.
A description is a brief summary of the agent’s role or specialization. This information is visible to other agents, and helps them understand the agent’s capabilities and expertise.
Instructions are specific instructions or guidelines for the agent to follow during task execution. These instructions are private and not shared with other agents.
Tools are Python functions that the agent can call to perform specific actions or computations. They are defined as a list of functions when creating an agent, and can be used to enhance the agent’s capabilities. The agent will have access to these tools in every task they are assigned to. If a task defines additional tools, the agent will have access to those as well.
Each agent has a model, which is the LLM that powers the agent responses. This allows you to choose the most suitable model for your needs, based on factors such as performance, latency, and cost.Marvin supports any model that is compatible with Pydantic AI. You can specify models using a string format like “openai:gpt-4” or by providing a Model instance:
Copy
Ask AI
import marvinfrom pydantic_ai.models import OpenAIModel# Using a string identifieragent1 = marvin.Agent(model="openai:gpt-4")# Using a model instancemodel = OpenAIModel(name="gpt-4")agent2 = marvin.Agent(model=model)
You can customize the behavior of an agent’s model using the model_settings parameter. This allows you to configure settings like temperature, top_p, etc:
Agents can be configured with memories that provide additional context or knowledge. These memories persist across tasks and can be used to store and retrieve relevant information:
In Marvin, agents can be organized into teams to work together on tasks. A team is a way to govern how agents collaborate.For a comprehensive guide on teams, see the Teams documentation page.
A swarm is a team of multiple agents that can freely collaborate and delegate tasks to each other. This is useful for complex tasks that require different types of expertise:
Agents must be assigned to tasks in order to work on them. You can assign agents by passing them to the agents parameter when creating a task:
Copy
Ask AI
import marvinagent = marvin.Agent(name="Poet")task = marvin.Task( instructions="Write a poem about AI", agents=[agent])
If no agent is specified, Marvin will use the default agent configured in your settings.You can also use the agent’s say method for simple conversational interactions:
Copy
Ask AI
import marvinagent = marvin.Agent(name="Assistant")response = agent.say("What is the meaning of life?")print(response)