0

Anthropic Provider

Anthropic Provider explains the cloud layer of MTPX with practical guidance for building inspectable, tool-using agents.

An
Anthropic Provider
Chapter 027ProvidersCloudIndex
01Orientation

Anthropic Provider belongs to the providers track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how anthropic provider affects a real MTPX agent before you wire it into an application.

  • What anthropic provider owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
from mtp import Agent
from mtp.providers import Groq

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
)
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

Anthropic Claude models with native tool-use API support. Uses Anthropic's block-based message format internally.

Install

bashpip install "mtpx[anthropic]"

Or install the SDK directly:

bashpip install anthropic

API Key Setup

  1. Install dotenv support:
bash   pip install python-dotenv

Or with the MTP extra:

bash   pip install "mtpx[dotenv]"
  1. Create a .env file in your project root:
text   ANTHROPIC_API_KEY=sk-ant-your_key_here
  1. Load it in your code before creating the provider:
python   from mtp import Agent

   Agent.load_dotenv_if_available()  # reads .env file

Get an API key at console.anthropic.com.

Option 2: System environment variable

bash# Linux/macOS
export ANTHROPIC_API_KEY="sk-ant-..."

# Windows PowerShell
$env:ANTHROPIC_API_KEY="sk-ant-..."

Quick Start

pythonfrom mtp import Agent
from mtp.providers import Anthropic

Agent.load_dotenv_if_available()  # loads ANTHROPIC_API_KEY from .env

provider = Anthropic(model="claude-3-5-sonnet-20241022")
tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools)

reply = agent.run_loop("What is 25 * 4 + 10?")
print(reply)

Parameters

ParameterTypeDefaultDescription
modelstr"claude-3-5-sonnet-20241022"Anthropic model ID
api_keystr | NoneNoneAPI key (falls back to ANTHROPIC_API_KEY env var)
max_tokensint1024Maximum tokens in the response
temperaturefloat0.0Sampling temperature
clientAny | NoneNonePre-configured anthropic.Anthropic client instance

Capabilities

CapabilityValue
Tool callingYes
Parallel tool callsYes
Input modalitiestext, image, file
StreamingFallback
Usage metricsRich
Reasoning metadataNo
Native asyncNo (uses thread fallback)
  • claude-3-5-sonnet-20241022 — Best balance of speed and capability (default)
  • claude-3-5-haiku-20241022 — Fastest, cheapest
  • claude-3-opus-20240229 — Most capable, slowest

Multimodal Support

Anthropic supports images and files (PDFs, documents) natively:

pythonfrom mtp.media import Image, File

provider = Anthropic(model="claude-3-5-sonnet-20241022")
agent = Agent(provider=provider, tools=tools)

# With image
reply = agent.run_loop({
    "content": "Describe this image",
    "images": [Image(filepath="photo.jpg")],
})

# With PDF document
reply = agent.run_loop({
    "content": "Summarize this document",
    "files": [File(filepath="report.pdf")],
})

Full Example

pythonfrom mtp import Agent
from mtp.providers import Anthropic

Agent.load_dotenv_if_available()

provider = Anthropic(
    model="claude-3-5-sonnet-20241022",
    max_tokens=4096,
    temperature=0.0,
)

tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools, debug_mode=True)

reply = agent.run_loop(
    "Calculate (25 * 4) + 10 and explain the steps.",
    max_rounds=4,
)
print(reply)

Notes

  • Anthropic uses a different internal message format (block-based with tool_use and tool_result content types), but MTP normalizes everything to the same event stream and ExecutionPlan semantics.
  • System prompts are sent as the system parameter, not as a message role.

Source

src/mtp/providers/anthropic_provider.py

01

Read

Understand where Anthropic Provider sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docCerebras Provider