Skip to main content

What is an Agent?

In mcp-agent, an Agent describes what the model is allowed to do. It captures:
  • A name and system-level instruction
  • The MCP servers (and optional local functions) that should be available
  • Optional behaviour hooks such as human-input callbacks or whether connections persist
On its own an agent is just configuration and connection management. The agent becomes actionable only after you attach an LLM implementation. Calling agent.attach_llm(...) (or constructing an AugmentedLLM with agent=...) returns an AugmentedLLM—an LLM with the agent’s instructions, tools, and memory bound in. You then use the AugmentedLLM to run generations, call tools, and chain workflows. Key ideas:
  • Agent = policy + tool access. It defines how the model should behave and which MCP servers or functions are reachable.
  • AugmentedLLM = Agent + model provider. Attaching an LLM binds a concrete provider (OpenAI, Anthropic, Google, Bedrock, etc.) and exposes generation helpers such as generate, generate_str, and generate_structured.
  • Agents are reusable. You can attach different AugmentedLLM providers to the same agent definition without rewriting instructions or server lists.

Creating Your First Agent

The simplest way to create an agent is through the Agent class. Define the instruction and servers, then attach an LLM to obtain an AugmentedLLM:
The value returned by attach_llm is an AugmentedLLM instance. It inherits the agent’s instructions and tool access, so every call to generate_str (or generate / generate_structured) can transparently read files, fetch URLs, or call any other MCP tool the agent exposes.

Tool Integration

Agents automatically discover and use tools from connected MCP servers, giving your LLM powerful capabilities.

Multi-Provider Support

Switch between different LLM providers (OpenAI, Anthropic, etc.) without changing your agent logic.

AgentSpec and factory helpers

AgentSpec (mcp_agent.agents.agent_spec.AgentSpec) is the declarative version of an agent: it captures the same fields (name, instruction, server_names, optional functions) and is used by workflows, config files, and factories. The helpers in mcp_agent.workflows.factory let you turn specs into agents or AugmentedLLMs with a single call.
Explore the agent factory examples to see how specs keep call sites small, how subagents can be auto-loaded from config, and how factories compose routers, orchestrators, and parallel pipelines.

Agent Configuration

Agents can be configured either programmatically or through configuration files. The framework supports both approaches, and each definition ultimately resolves to an AgentSpec:

Configuration File Approach

Create a mcp_agent.config.yaml file to define your agent’s environment:

Programmatic Configuration

You can also configure agents directly in code:

Agent Capabilities

Once an agent has an AugmentedLLM attached, it gains the following capabilities:

Multi-LLM Provider Support

Switch between different LLM providers seamlessly:

Advanced Model Selection

Control model selection with preferences:

Human Input Integration

Agents can request human input during execution:

Memory and Context Management

Agents maintain conversation history automatically:

Agent Lifecycle Management

Agents follow a predictable lifecycle:

1. Initialization

When you create an agent, it:
  • Loads configuration from files or code
  • Connects to specified MCP servers
  • Discovers available tools and capabilities

2. Usage

During operation, the agent:
  • Processes user requests through the LLM
  • Orchestrates tool calls as needed
  • Maintains conversation history
  • Handles errors and retries

3. Cleanup

When finished, the agent:
  • Closes connections to MCP servers
  • Releases resources
  • Saves any persistent state

Common Usage Patterns

Application Integration

Use the MCPApp class for full application setup:

Tool Discovery

Explore what tools are available to your agent:
This covers the essential concepts users need to understand and effectively use agents in the mcp-agent framework.