A minimal agent framework with first-class tracing, callbacks, MCP, and serving support.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39fd9d0c6138eb6d1e0fd29ecca7528e7b4fd3d862b3ec1afb5e31971fc18cc3
|
|
| MD5 |
1b0b11592685c32336b78bca00c87bc1
|
|
| BLAKE2b-256 |
a0bbdf846f0cf29715f8901af182b44fdf6878a15408af10a5bb6585a3fc5d6c
|
Provenance
The following attestation bundles were made for mozilla_ai_tinyagent-0.1.0.tar.gz:
Publisher:
release.yaml on mozilla-ai/tinyagent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mozilla_ai_tinyagent-0.1.0.tar.gz -
Subject digest:
39fd9d0c6138eb6d1e0fd29ecca7528e7b4fd3d862b3ec1afb5e31971fc18cc3 - Sigstore transparency entry: 1400849710
- Sigstore integration time:
-
Permalink:
mozilla-ai/tinyagent@3c6ceac1cda24bb71e3a001ba4b5d64ffaf841d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mozilla-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@3c6ceac1cda24bb71e3a001ba4b5d64ffaf841d9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mozilla_ai_tinyagent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mozilla_ai_tinyagent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 61.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ea4eab013f037281b853ce333b8a4a1538aeaef60a43c9643e77262dcc85c8c
|
|
| MD5 |
0a290202389b702d92bfca94060bc4b0
|
|
| BLAKE2b-256 |
07f06ed600f2fe9c4ebab975aee279a16be08b5c2d9b55d9ae83628031c96a43
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mozilla_ai_tinyagent-0.1.0-py3-none-any.whl -
Subject digest:
2ea4eab013f037281b853ce333b8a4a1538aeaef60a43c9643e77262dcc85c8c - Sigstore transparency entry: 1400849883
- Sigstore integration time:
-
Permalink:
mozilla-ai/tinyagent@3c6ceac1cda24bb71e3a001ba4b5d64ffaf841d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mozilla-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@3c6ceac1cda24bb71e3a001ba4b5d64ffaf841d9 -
Trigger Event:
release
-
Statement type: