Skip to main content

Troop

Build and manage AI agents from the CLI with PydanticAI and Model Context Protocol.

Introduction

Troop is a lightweight CLI wrapper around PydanticAI and the Model Context Protocol (MCP). It enables users to easily create, customize, manage, and interact with AI agents through a simple yet powerful command line interface.

troop researcher -p "Any music events in Paris tonight?"

Researcher: There are multiple music events in Pari...

Think of troop as a generalized version of Claude Code, that allows you to build and use all kinds of useful agents based on any LLM you like.

In troop, an AI agent consists of 3 parts:

  1. Model: Choose any LLM from any supported provider as the backbone of your agent.
  2. Tools: Every tool in troop is provided through an MCP server. Mix and match as many as you like, remote or locally.
  3. Instructions: Tie everything together and let the agent know how to act and which tools to use in what situation.

Agent = Model + Tools + Instructions

Features

  • Async-First Architecture: Built with asyncio for efficient concurrent operations
  • PydanticAI: As the core engine to manage requests and responses with different providers
  • MCP: As a single interface for tool usage
  • Modern CLI Experience: Beautiful terminal interface using Typer and Rich
  • REPL: Nicely formatted display of Human, Agent, and Tool messages
  • Agent Registry: Add and manage agents to your needs

Installation

We recommend using uv to install troop:

uv tool install troop

Or with pip:

pip install troop

Quick Start

Let's build and run our first custom agent.

1. Add a Provider

troop provider add
# Enter provider name/ID: openai
# Enter API key: sk-abcd...

This adds OpenAI as a model provider making all their models available in troop. We support all PydanticAI providers.

2. Add an MCP Server

troop mcp add
# Enter name: web-tools
# Enter command: uvx mcp-web-tools
# Enter env var: BRAVE_SEARCH_API_KEY=abc...

This adds a predefined MCP server called mcp-web-tools with its search and fetch tools using uv, and accesses it directly from PyPI.

3. Create an Agent

troop agent add
# Enter name: researcher
# Enter model: openai:gpt-4o
# Enter MCP servers: web-tools
# Enter instructions: You're a helpful researcher agent with access to the web...

This defines the actual agent with the model, tools and instructions.

4. Use Your Agent

troop researcher

> What's the first headline on the Guardian?

> "Climate Summit Reaches Historic Agreement on Emissions"

This launches the interactive REPL for the researcher agent we just created.

Commands Overview

Agent Invocation

# Interactive chat mode (default)
troop researcher

# Single prompt mode
troop researcher -p "What's the weather in Paris?"

# Override model
troop researcher -m openai:gpt-4o-mini

Provider Management

# List providers
troop provider list

# Add provider
troop provider add openai --api-key sk-abc123...

# Remove provider
troop provider remove openai

MCP Server Management

# List servers
troop mcp list

# Add server
troop mcp add

# Remove server
troop mcp remove web-tools

Agent Management

# List agents
troop agent list

# Add agent
troop agent add

# Remove agent
troop agent remove researcher

# Set default agent
troop agent set researcher

Model Management

# Set default model
troop model set openai:gpt-4o

Configuration

Troop stores a global config YAML file in the user directory:

  • macOS: ~/.troop/config.yaml
  • Linux: ~/.config/troop/config.yaml
  • Windows: %APPDATA%/troop/config.yaml

Example configuration:

providers:
  openai: sk-proj-vBAU...
  anthropic: sk-ant-api...
servers:
  web_tools:
    command:
    - uvx
    - mcp-web-tools
    env:
      BRAVE_SEARCH_API_KEY: BSA-abc123...
agents:
  researcher:
    model: openai:gpt-4o
    instructions: You're a helpful researcher with access to web tools...
    servers:
    - web_tools
defaults:
  model: openai:gpt-4o
  agent: researcher

REPL Experience

Troop provides a rich interactive experience in the terminal, with clear formatting for different message types:

┌─ User ────────────────────────────────────────────────────────────────┐
│ What is the Model Context Protocol?                                   │
└───────────────────────────────────────────────────────────────────────┘

┌─ Tool Call: web_tools-search_web ─────────────────────────────────────┐
│ {                                                                     │
│   "query": "Model Context Protocol",                                  │
│ }                                                                     │
└───────────────────────────────────────────────────────────────────────┘

┌─ Researcher ──────────────────────────────────────────────────────────┐
│ The Model Context Protocol (MCP) is an open standard created by       │
│ Anthropic that enables secure, two-way connections between AI systems │
│ and external data sources or tools.                                   │
└───────────────────────────────────────────────────────────────────────┘

Best Practices

System Instructions vs. Tool Descriptions

When defining agents and their tools, consider:

  • Tool Description: Explain what the tool does, what it returns and HOW it needs to be used on a technical level. There shouldn't be any mentions of other tools or servers.
  • System Instructions: Explain WHEN and in what situation a tool should be used or favored over another. Focus on the overall process the agent will go through.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for troop 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for troop 0.2.0
File Size Uploaded
troop-0.2.0.tar.gz 69.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for troop 0.2.0
File Interpreter ABI Platform
troop-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.0 kB

Release files / troop-0.2.0.tar.gz

Download URL troop-0.2.0.tar.gz
Size 69.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e97cb64c4036a309b33648f038b31bdc374dd3aa5442aa97a8cb5c1e46a3df
BLAKE2b-256 checksum
How to use checksums
c5ff06f2f822a9bfff96f1401ba34281ff248c20a32660f43aade3beb81cf989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.10

Release files / troop-0.2.0-py3-none-any.whl

Download URL troop-0.2.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27dc874496f97ada96d88e8d7e25d4136058d456416e75e52922f7eb151f7c1c
BLAKE2b-256 checksum
How to use checksums
bf968e936c3e892acd7c9d1527d7943bea8f34e2993ebe00199265145b3f87fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page