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.1.tar.gz (131.4 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.1-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mozilla_ai_tinyagent-0.1.1.tar.gz
  • Upload date:
  • Size: 131.4 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.1.tar.gz
Algorithm Hash digest
SHA256 a15cb18c7e56c1b8a6b3670540e58fc65f6d156457855a600ea14ff8b4cfc322
MD5 c6d4b5515fd1f97379db85f6e23e7cd0
BLAKE2b-256 129cb39db097e64c5d12e64c51fb28b97a9ca601b550d892d829166a75509a64

See more details on using hashes here.

Provenance

The following attestation bundles were made for mozilla_ai_tinyagent-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mozilla_ai_tinyagent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dae0bedde71fc2edf68036523d66f008612f5070bab8ef027964574c30c22f4b
MD5 e82a45050d843f109ea87874071713f3
BLAKE2b-256 4d69e9bffd45ff74853a4277d126f1050be5891c717830d2ec2a1be4ceb67094

See more details on using hashes here.

Provenance

The following attestation bundles were made for mozilla_ai_tinyagent-0.1.1-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