Skip to main content

pico-agent

DEPRECATED. This package is no longer maintained and receives no further releases. Version 0.2.1 is the final release; it fixes compatibility with pico-ioc >= 2.4.0 so existing installs keep working. The rest of the pico ecosystem is unaffected and actively maintained.

PyPI Ask DeepWiki License: MIT CI (tox matrix) codecov Quality Gate Status Duplicated Lines (%) Maintainability Rating Docs

Pico-Agent

Pico-Agent is a lightweight, protocol-based framework for building modular AI agents using dependency injection.

It eliminates the boilerplate of manually managing LLM chains, prompts, and tools. Instead, you declare what you want the agent to do using Python Protocols, and the framework handles how to execute it via Pico-IoC.

Protocol-First Design True Dependency Injection Smart Model Routing Multi-Agent Orchestration LLM Agnostic (LangChain based)


Why pico-agent?

Most agent frameworks require you to instantiate classes, manually bind tools, and hardcode model names. Pico-Agent moves this complexity into the IoC container, promoting clean architecture and testability.

Feature Standard Approach Pico-Agent
Definition Concrete Classes / Functions Python Protocols (Interfaces)
Discovery Manual Instantiation Auto-scanning via IoC
Tools Manual Binding DI Injection & Name Reference
Configuration Global Env Vars Injected Configuration Components
Orchestration Complex Chains Agents using Agents as Tools

Core Features

  • Declarative Agents: Use @agent on standard typing.Protocol.
  • Capability Routing: Request FAST, SMART, CODING capabilities instead of specific model names.
  • Auto-Discovery: Leverages pico-ioc 2.2+ custom scanners to find agents automatically.
  • Type-Safe: Full support for Pydantic input/output schemas.
  • ReAct Loops: Built-in support for reasoning loops and tool usage.

Installation

pip install pico-agent

Install with specific provider support:

pip install "pico-agent[openai,google]"

Quick Example

1. Define the Agent Protocol

The method signature defines the tool input. The @agent decorator configures everything else.

from typing import Protocol
from pico_agent import agent, AgentCapability, AgentType

@agent(
    name="translator",
    capability=AgentCapability.FAST,  # Uses a faster/cheaper model
    system_prompt="You are a professional translator.",
    user_prompt_template="Translate this to Spanish: {text}",
    agent_type=AgentType.ONE_SHOT
)
class TranslatorAgent(Protocol):
    def translate(self, text: str) -> str: ...

2. Configure Credentials

Inject the centralized LLMConfig and set your keys. This avoids hardcoded environment variable lookups inside the library.

import os
from pico_ioc import component, configure
from pico_agent import LLMConfig

@component
class AppConfig:
    @configure
    def setup_llm(self, config: LLMConfig):
        # Load from Env, Vault, AWS Secrets, etc.
        config.api_keys["openai"] = os.getenv("OPENAI_API_KEY")
        config.api_keys["google"] = os.getenv("GOOGLE_API_KEY")

3. Run the Application

pico-agent includes its own init() that wraps pico_ioc.init() with automatic module inclusion and plugin discovery:

from pico_agent import init
from app.agents import TranslatorAgent

def main():
    # Scans modules, finds agents, wires dependencies
    container = init(modules=["app"])

    # Get your agent instance (auto-generated proxy)
    translator = container.get(TranslatorAgent)

    result = translator.translate(text="Dependency Injection is cool")
    print(result)

if __name__ == "__main__":
    main()

You can also use pico_ioc.init() directly — just include "pico_agent" in your modules list:

from pico_ioc import init

container = init(modules=["pico_agent", "app"])

Advanced Usage

ReAct Agents & Tools

Agents can use any dependency in the container as a tool.

# 1. Define a tool (standard component)
from pico_ioc import component

@component
class Calculator:
    def add(self, a: int, b: int) -> int:
        """Adds two numbers."""
        return a + b

# 2. Define the Agent
@agent(
    name="math_expert",
    capability=AgentCapability.REASONING,
    agent_type=AgentType.REACT,  # Enables Reasoning Loop
    tools=["calculator"],        # Reference tool by name (snake_case of class)
    max_iterations=5
)
class MathAgent(Protocol):
    def solve(self, problem: str) -> str: ...

Multi-Agent Orchestration

An agent can use other agents as tools simply by referencing them.

@agent(
    name="orchestrator",
    capability=AgentCapability.SMART,
    system_prompt="Coordinate the sub-agents to solve the task.",
    # Inject other agents as tools available to this LLM
    agents=["translator", "math_expert"] 
)
class Orchestrator(Protocol):
    def handle_request(self, task: str) -> str: ...

Model Routing & Configuration

pico-agent uses semantic capabilities to route to specific models. You can configure this globally using a configurer.

from pico_ioc import component, configure
from pico_agent.router import ModelRouter, AgentCapability

@component
class RouterConfig:
    @configure
    def configure_router(self, router: ModelRouter):
        # Update default mappings
        router.update_mapping(AgentCapability.FAST, "openai:gpt-5-mini")
        router.update_mapping(AgentCapability.SMART, "anthropic:claude-4-5-sonnet")
        
        # You can also use "provider:model" syntax
        router.update_mapping(AgentCapability.CODING, "deepseek:deepseek-coder")

With pico-boot

If you use pico-boot, pico-agent is automatically discovered via entry points — no need to include it in your modules list:

from pico_boot import init

container = init(modules=["app"])
# pico-agent is auto-discovered and loaded!

Testing

Testing is simple because you can mock the underlying LLMFactory or the agent protocol itself.

from unittest.mock import MagicMock
from pico_ioc import init
from pico_agent import LLMFactory, LLM

def test_my_agent():
    mock_llm = MagicMock(spec=LLM)
    mock_llm.invoke.return_value = "Mocked Response"
    
    mock_factory = MagicMock(spec=LLMFactory)
    mock_factory.create.return_value = mock_llm
    mock_factory.return_value = mock_factory # For singleton resolution

    container = init(
        modules=["pico_agent", "my_app"],
        overrides={LLMFactory: mock_factory},
    )
    
    agent = container.get(MyAgent)
    assert agent.run("test") == "Mocked Response"

AI Coding Skills

Install Claude Code or OpenAI Codex skills for AI-assisted development with pico-agent:

curl -sL https://raw.githubusercontent.com/dperezcabrera/pico-skills/main/install.sh | bash -s -- agent
Command Description
/add-agent Add LLM agents and tools
/add-component Add components, factories, interceptors, settings
/add-tests Generate tests for pico components

All skills: curl -sL https://raw.githubusercontent.com/dperezcabrera/pico-skills/main/install.sh | bash

See pico-skills for details.


License

This project is licensed under the MIT License.

Metadata

Release files for pico-agent 0.2.1

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

Source distribution (sdist)

Source distribution for pico-agent 0.2.1
File Size Uploaded Provenance
pico_agent-0.2.1.tar.gz 91.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pico-agent 0.2.1
File Interpreter ABI Platform
pico_agent-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 136.7 kB

Release files / pico_agent-0.2.1.tar.gz

Download URL pico_agent-0.2.1.tar.gz
Size 91.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0250339e7243963b2161e8af19565545f1b17f9771925efe8b0f0064f2e48e79
BLAKE2b-256 checksum
How to use checksums
505f7311b1161a2c556d8459ff34b92467d3caa1d90699e7b9c0bb4460483d8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Release files / pico_agent-0.2.1-py3-none-any.whl

Download URL pico_agent-0.2.1-py3-none-any.whl
Size 44.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e592b8d44aaf6847a737578b7ef956438a5a3b1d987257e1f2d95bce82a0df5a
BLAKE2b-256 checksum
How to use checksums
dfcd6b096682662f28255cb747cbbf33dbc0cc1a34d25a603fa15fcbf60a2f9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Security for pico-agent 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pico_agent-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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