Skip to main content
Agents are autonomous AI units that have their own LLM provider, can execute tools, and are themselves callable as tools. They enable sophisticated multi-agent architectures where specialized agents can be composed and orchestrated.
Agents build on the MCP Tools specification—each agent is automatically exposed as an invoke_<agent-id> tool that any MCP client can call.

Why Agents?

In the Model Context Protocol, agents serve a distinct purpose from tools, resources, and prompts: Agents are ideal for:
  • Complex reasoning — tasks requiring multiple LLM calls and tool use
  • Specialized expertise — domain-specific agents (research, writing, coding)
  • Orchestration — coordinating multiple sub-agents for complex workflows
  • Isolation — agents with their own tools, resources, and providers

Creating Agents

Class Style (Default Behavior)

The simplest agent requires no execute() method. The default behavior automatically:
  • Runs the execution loop with the LLM
  • Connects tools and executes them as needed
  • Sends notifications on tool calls and output

Class Style (Custom Behavior)

Override execute() only when you need custom pre/post processing:

Function Style

For simpler agents, use the functional builder:

Registering Agents

Add agents to your app via the agents array:
Each agent is automatically exposed as a tool:
  • invoke_research-agent
  • invoke_calculator-agent
  • invoke_writer-agent

LLM Configuration

Agents require an LLM configuration. FrontMCP uses LangChain as the standard adapter layer, providing consistent APIs across all LLM providers with built-in retry logic, streaming support, and token tracking.

Using LangChain Adapters

First, install the LangChain package for your provider:

OpenAI

Anthropic

OpenRouter

Access 100+ models through OpenRouter using the OpenAI-compatible API:

Custom Adapter

Implement AgentLlmAdapter for providers not covered by LangChain:

Agent-Scoped Components

Agents can have their own isolated tools, resources, prompts, and providers:

Swarm Configuration

Control agent visibility for multi-agent coordination:

Visibility Patterns

Orchestrator Pattern — A central agent coordinates specialized workers:

Execution Configuration

Control agent execution behavior:

Tool Execution Mode

By default, agents execute tools through the full call-tool flow, which includes:
  • Plugin hooks (caching, rate limiting, audit logging)
  • Authorization checks
  • Tool middleware and transformations
For performance-critical scenarios, you can disable flow execution:
Setting useToolFlow: false bypasses all plugin hooks and middleware. Only use this when you need maximum performance and don’t require plugin features.

Overriding Behavior

Customize agent behavior by overriding methods in AgentContext:

Progress Notifications

Keep users informed during long operations using manual or automatic notifications.

Manual Notifications

Use this.notify() to send custom messages at specific points:
Use this.progress() for progress bars when the client provides a progressToken:

Automatic Progress (Opt-in)

Enable enableAutoProgress to automatically send progress notifications during the agent execution loop:
When enabled, the agent automatically sends progress updates at these lifecycle points:
Auto progress requires both enableAutoProgress: true and enableNotifications: true (the default). Progress notifications are only sent if the client includes a progressToken in the request’s _meta field.

Error Handling

Handle errors gracefully in agents:

Nested Agents

Agents can contain other agents, creating hierarchical structures: