Skip to main content

A lightweight, extensible framework for building LLM agents with Model Context Protocol (MCP) support

Project description

Pocket-Agent

Pocket Agent

A lightweight, extensible framework for building LLM agents with Model Context Protocol (MCP) support

PyPI - Version License


Table of Contents


Why Pocket Agent?

Most agent frameworks are severely over-bloated. The reason for this is that they are trying to support too many things at once and make every possible agent implementation "simple". In the end, you might find yourself using 5-10% of the framework's code for your use case, meaning 90-95% is noise when you encounter a bug. This makes adding features and debugging unnecessarily complex.

Pocket Agent takes the opposite approach by implementing the basic functionalities of an Agent as an abstraction one layer above the MCP Client with useful features to provide first-class support for customization. This makes Pocket Agent extremely lightweight. In fact, so lightweight that the entire core framework and documentation can easily fit into most LLM context windows (see the built-in utility for this here). The minimal nature also means that you will use 90-95% of the framework's code for every agent you create.

Despite the minimal code, Pocket Agent is extremely powerful, even out-of-the-box with no custom extensions. By default, Pocket Agent enables users to:

  • Use any remote or local MCP server(s) to integrate any amount of custom tools
  • Run a typical agent loop (generate message, execute tool calls, handle tool results until the LLM does not call any tools)
  • Allow tools to be run in parallel, minimizing execution bottlenecks
  • Build multi-agent systems using built-in features to facilitate interaction
  • View agents' behavior in a minimal built-in CLI frontend
  • Use any local or remote LLM and enforce tpm/rpm limits for parallel LLM generations (Thanks to LiteLLM)

Design Principles

🚀 Lightweight & Simple

  • Clean abstractions that separate agent logic from MCP client details
  • Core functionality is only 2 files
  • Only implements the core, non-case-specific features of an LLM agent

💡 Extensible

  • Easily integrate a custom frontend using the built-in event system
  • Easily implement fully custom agent behaviors
  • Easily develop multi-agent systems

Installation

Install with uv (Recommended):

uv add pocket-agent

Install with pip:

pip install pocket-agent

Quick Start (For LLMs)

LLMs are excellent at building with Pocket Agent. Mostly, because the entirety of the core framework is minimal enough to easily fit into most LLM context windows.

Pocket Agent provides a simple command-line utility for this exact use case: pocket-dump

📄 Using pocket-dump

After installation, use pocket-dump to generate complete documentation with source code:

# Generate complete documentation + source code as pocket-agent-source.md
pocket-dump

# Custom filename
pocket-dump my-pocket-agent-reference.md

# Only include documentation
pocket-dump --docs-only

# Only include source code  
pocket-dump --source-only

The generated file contains everything an LLM needs to understand and build with Pocket Agent - no need to piece together multiple documentation sources or guess at implementation details.

Quick Start (For Humans)

You can use PocketAgent out of the box in 3 steps:

  1. Configure the agent:

    from pocket_agent import AgentConfig
    
    # Configure and run
    config = AgentConfig(
        llm_model="gpt-4",
        system_prompt="You are a helpful assistant."
    )
    
  2. Define the mcp servers the agent can access:

    servers = {
        "mcpServers": {
            "weather_tools": {
                "transport": "stdio",
                "command": "python",
                "args": ["server.py"],
                "cwd": "path/to/server.py
            }
        }
    }
    
  3. Initialize and run the agent:

    import asyncio
    from pocket_agent import PocketAgent
    
    agent = PocketAgent(agent_config=config, mcp_config=servers)
    
    agent_final_answer = await agent.run("What's the weather fo London?")
    

In the above example, the run method will add the input as a user message, and then run in a loop generating new messages and running any tools called by the configured LLM until the configured LLM generates a response which does not have any tool calls. All of the messages to and from the agent are neatly formatted in the console by default.

Pocket Agents are meant to be extended far beyond this behavior. Refer to the sections below for implementation examples and full documentation

🧑‍🍳 Cookbook

Find example implementations of Pocket Agents and their extensions in the Cookbook

📖 Documentation

For comprehensive documentation on all features and advanced usage, see the documentation folder:

Feature Roadmap

Core Features

Feature Status Priority Description
Agent Abstraction ✅ Implemented - Basic agent abstraction with PocketAgent base class
MCP Protocol Support ✅ Implemented - Full integration with Model Context Protocol via fastmcp
Multi-Model Support ✅ Implemented - Support for any LiteLLM compatible model/endpoint
Tool Execution ✅ Implemented - Automatic parallel tool calling and results handling
Hook System ✅ Implemented - Allow configurable hooks to inject functionality during agent execution
Logging Integration ✅ Implemented - Built-in logging with custom logger support
Multi-Agent Integration ✅ Implemented - Allow a PocketAgent to accept other PocketAgents as Sub Agents and automatically set up Sub Agents as tools for the Agent to use
function-as-a-tool support 📋 Planned Medium Allow python functions to be passed to PocketAgent to act as tools
**Define Defaults for standard MCP Client handlers 📋 Planned Medium Standard MCP client methods (i.e. sampling, progress, etc) may benefit from default implementations if custom behavior is not often needed
Streaming Responses 📋 Planned Medium Real-time response streaming support
**Define Defaults for standard MCP Client handlers 📋 Planned Medium Standard MCP client methods (i.e. sampling, progress, etc) may benefit from default implementations if custom behavior is not often needed
Resources Integration 📋 Planned Medium Automatically set up mcp read_resource functionality as a tool (resources are not very commonly used today so this may not be necessary)

Modality support

Modality Status Priority Description
Text ✅ Implemented - Multi-modal input support for vision models
Images ✅ Implemented - Multi-modal input support for VLMs with option to enable/disable
Audio 📋 Planned Low Multi-modal input support for LLMs which allow audio inputs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pocket_agent-0.2.23.tar.gz (5.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocket_agent-0.2.23-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file pocket_agent-0.2.23.tar.gz.

File metadata

  • Download URL: pocket_agent-0.2.23.tar.gz
  • Upload date:
  • Size: 5.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for pocket_agent-0.2.23.tar.gz
Algorithm Hash digest
SHA256 a251d420ee7493d652279e4b3cb81329731a33228f1e12ab00361feb9fbe5393
MD5 f1ccc0110038fbb48ce118f5339eb75f
BLAKE2b-256 36f92f06a7dc7d6f3f6d62ed6807179fa8224dff18531f398fa20efe638cb0c9

See more details on using hashes here.

File details

Details for the file pocket_agent-0.2.23-py3-none-any.whl.

File metadata

  • Download URL: pocket_agent-0.2.23-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for pocket_agent-0.2.23-py3-none-any.whl
Algorithm Hash digest
SHA256 f1c1b49f5fc7efb03964ce704321251eb27b25a828968bdb28b861181f9c46cd
MD5 d0f4826143add38e6e169407d7502b78
BLAKE2b-256 71e490e810ace73f2f069e20b8272b7d8d57a5bc0cf81d4866e7c4b582de0b18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page