Skip to main content

A minimal agent framework with first-class tracing, callbacks, MCP, and serving support.

Project description

tinyagent

Python 3.11+ PyPI

A minimal agent framework with first-class tracing, callbacks, MCP, and serving.

What this is

tinyagent is a small, dependency-light Python implementation of the HuggingFace Tiny Agents loop, built on any-llm. It gives you:

  • A simple agent loop you can read in one sitting.
  • Native MCP tool support (stdio, SSE, streamable HTTP).
  • OpenTelemetry-based tracing of LLM calls and tool executions, including token counts and cost.
  • A callback system for guardrails, metrics, and intentional cancellation.
  • Optional A2A and MCP serving so your agent can run as a service.

This package was extracted from any-agent, which still uses tinyagent under the hood as one of its supported framework backends.

Install

pip install mozilla-ai-tinyagent

The PyPI distribution name is mozilla-ai-tinyagent; the import name is tinyagent.

Optional extras:

pip install 'mozilla-ai-tinyagent[a2a]'       # A2A serving
pip install 'mozilla-ai-tinyagent[composio]'  # Composio tools
pip install 'mozilla-ai-tinyagent[all]'       # everything

Quickstart

from tinyagent import TinyAgent, AgentConfig
from tinyagent.tools import search_web, visit_webpage

agent = TinyAgent.create(
    AgentConfig(
        model_id="mistral:mistral-small-latest",
        instructions="Use the tools to find an answer.",
        tools=[search_web, visit_webpage],
    )
)

trace = agent.run("Which agent framework is the simplest?")
print(trace.final_output)

model_id follows the any-llm provider syntax (provider:model). Set the relevant API key (e.g. MISTRAL_API_KEY, OPENAI_API_KEY) in your environment.

Use MCP tools

from tinyagent import TinyAgent, AgentConfig
from tinyagent.config import MCPStdio

agent = TinyAgent.create(
    AgentConfig(
        model_id="mistral:mistral-small-latest",
        instructions="Use the available tools to answer.",
        tools=[
            MCPStdio(command="uvx", args=["duckduckgo-mcp-server"]),
        ],
    )
)

trace = agent.run("What is the capital of Pennsylvania?")
print(trace.final_output)

Tracing

Every agent.run(...) returns an AgentTrace with the final output, the spans, token counts, and cost.

trace = agent.run("...")
print(trace.duration)
print(trace.tokens)
print(trace.cost)
for span in trace.spans:
    print(span.name, span.attributes)

Callbacks

Subclass Callback to observe or control execution. Each hook receives a Context and returns it, optionally mutating shared state.

from tinyagent.callbacks import Callback, Context

class LimitToolCalls(Callback):
    def before_tool_execution(self, context: Context, *args, **kwargs) -> Context:
        context.shared["count"] = context.shared.get("count", 0) + 1
        if context.shared["count"] > 5:
            raise StopIteration("Too many tool calls")
        return context

See AgentCancel for cancellation that preserves the trace.

Serve as a service

from tinyagent.serving import MCPServingConfig

agent = TinyAgent.create(...)
handle = await agent.serve_async(MCPServingConfig(port=8080))

A2A serving is available with the [a2a] extra.

Running in Jupyter

import nest_asyncio
nest_asyncio.apply()

License

Apache 2.0.

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

mozilla_ai_tinyagent-0.1.0.tar.gz (130.5 kB view details)

Uploaded Source

Built Distribution

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

mozilla_ai_tinyagent-0.1.0-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file mozilla_ai_tinyagent-0.1.0.tar.gz.

File metadata

  • Download URL: mozilla_ai_tinyagent-0.1.0.tar.gz
  • Upload date:
  • Size: 130.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mozilla_ai_tinyagent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39fd9d0c6138eb6d1e0fd29ecca7528e7b4fd3d862b3ec1afb5e31971fc18cc3
MD5 1b0b11592685c32336b78bca00c87bc1
BLAKE2b-256 a0bbdf846f0cf29715f8901af182b44fdf6878a15408af10a5bb6585a3fc5d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mozilla_ai_tinyagent-0.1.0.tar.gz:

Publisher: release.yaml on mozilla-ai/tinyagent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mozilla_ai_tinyagent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mozilla_ai_tinyagent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea4eab013f037281b853ce333b8a4a1538aeaef60a43c9643e77262dcc85c8c
MD5 0a290202389b702d92bfca94060bc4b0
BLAKE2b-256 07f06ed600f2fe9c4ebab975aee279a16be08b5c2d9b55d9ae83628031c96a43

See more details on using hashes here.

Provenance

The following attestation bundles were made for mozilla_ai_tinyagent-0.1.0-py3-none-any.whl:

Publisher: release.yaml on mozilla-ai/tinyagent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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