Define tools and agents as code. Run them anywhere.
Project description
smalltask
Define tools and agents as code. Run them anywhere.
pip install smalltask
smalltask is a lightweight framework for building scheduled AI agents. Tools are Python functions. Agents are YAML files. Both live in your git repo — diffable, reviewable, auditable.
Bring your own scheduler (Airflow, cron, GitHub Actions). Bring your own LLM (any OpenAI-compatible endpoint).
Quickstart
smalltask init # scaffold tools/ and agents/
smalltask init --template github # scaffold GitHub tools + PR digest agent
Then run:
smalltask run agents/example.yaml --var topic="revenue drop" --verbose
How it works
Tools are @tool-decorated Python functions. The function is the security boundary — the agent can only do what you explicitly expose.
# tools/orders.py
from smalltask import tool
@tool
def get_order_summary(days: int) -> dict:
"""Return aggregated order stats for the last N days."""
...
@tool
def get_top_customers(days: int, limit: int) -> list:
"""Return the top customers by spend in the last N days."""
...
Agents are YAML files. They declare the prompt, which tools to use, and which LLM endpoint to call.
# agents/weekly_review.yaml
name: weekly_review
description: Weekly order digest with anomaly detection.
llm:
url: https://openrouter.ai/api/v1/chat/completions
model: anthropic/claude-3.5-sonnet
api_key_env: OPENROUTER_API_KEY
prompt: |
You are a data analyst reviewing the last 7 days of orders.
Summarise volume, revenue, refund rate, and top customers.
Flag anything unusual. Be direct. Use numbers.
tools:
- orders.get_order_summary
- orders.get_top_customers
Reference tools as file.function to be explicit and avoid name collisions.
Use $varname in prompts for runtime variables:
prompt: |
Review orders for the week of $week.
...
smalltask run agents/weekly_review.yaml --var week=2024-W01
Project structure
your-repo/
├── tools/
│ ├── orders.py # get_order_summary, get_top_customers, ...
│ ├── github.py # list_open_prs, get_workflow_runs, ...
│ └── slack.py # post_message, ...
├── agents/
│ ├── weekly_review.yaml
│ └── github_pr_digest.yaml
└── dags/
└── weekly_review_dag.py # optional: Airflow integration
Tools are discovered from the tools/ directory. Agent YAMLs reference them by name.
Schedulers
smalltask doesn't own scheduling — it drops into whatever you already have.
GitHub Actions
The fastest way to get a scheduled agent running. No infrastructure required.
# .github/workflows/weekly_review.yml
name: Weekly order review
on:
schedule:
- cron: '0 9 * * 1' # every Monday at 9am UTC
workflow_dispatch: # also allow manual runs from the GitHub UI
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install smalltask
- run: smalltask run agents/weekly_review.yaml --var week=$(date +%Y-W%V)
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
Store your API key under Settings → Secrets → Actions in the GitHub repo.
Cron
# crontab -e
0 9 * * 1 cd /path/to/repo && smalltask run agents/weekly_review.yaml --var week=$(date +\%Y-W\%V) >> /var/log/smalltask.log 2>&1
Airflow
from airflow.operators.python import PythonOperator
from smalltask.runner import run_agent
from pathlib import Path
PythonOperator(
task_id="weekly_review",
python_callable=run_agent,
op_kwargs={
"agent_path": Path("agents/weekly_review.yaml"),
"input_vars": {"week": "{{ ds }}"},
},
)
Python
from smalltask.runner import run_agent
from pathlib import Path
result = run_agent(
agent_path=Path("agents/weekly_review.yaml"),
input_vars={"week": "2024-W01"},
)
Agent YAML reference
| Field | Required | Description |
|---|---|---|
name |
yes | Agent identifier |
description |
no | Human-readable description |
prompt |
yes | System prompt. Supports $var interpolation. |
tools |
yes | List of tool names (file.function or bare function) |
llm.url |
yes | OpenAI-compatible endpoint URL |
llm.model |
yes | Model identifier |
llm.api_key_env |
no | Name of env var holding the API key |
llm.max_tokens |
no | Max tokens per LLM call (default: 4096) |
llm.timeout |
no | HTTP timeout in seconds (default: 120) |
llm.extra_headers |
no | Additional HTTP headers (e.g. HTTP-Referer) |
max_iterations |
no | Max agentic loop iterations (default: 20) |
max_total_tokens |
no | Token budget across all iterations — stops early if exceeded (default: no limit) |
pre_hook |
no | List of tool calls to run before the LLM loop (see Hooks) |
post_hook |
no | List of tool calls to run after the LLM loop (see Hooks) |
Hooks
Hooks let you run deterministic tool calls before and after the LLM loop. They use the same tools you already have — no new concepts.
name: metrics_alert
prompt: |
Analyze the attached metrics. Flag anomalies. Be direct.
llm:
url: https://openrouter.ai/api/v1/chat/completions
model: anthropic/claude-3.5-sonnet
api_key_env: OPENROUTER_API_KEY
tools:
- analysis.plot_revenue
- analysis.get_summary
pre_hook:
- analysis.snapshot_metrics:
days: 7
- analysis.check_threshold:
metric: error_rate
max: 0.05
post_hook:
- reporting.upload_charts
- reporting.send_slack_report:
channel: "#alerts"
Pre-hooks
Pre-hooks run sequentially before the LLM. Their results are injected into the prompt so the LLM can see the data.
Each entry is a tool name with optional args:
pre_hook:
- orders.get_summary:
days: 7
- orders.check_threshold:
metric: refund_rate
max: 0.05
Skip gate — if a pre-hook returns {"skip": True}, the agent stops immediately without calling the LLM. Use this to avoid wasting tokens when there's nothing to act on:
@tool
def check_threshold(metric: str, max: float) -> dict:
"""Only run the agent if a metric exceeds a threshold."""
value = get_current_value(metric)
if value <= max:
return {"skip": True, "reason": f"{metric} is {value}, below {max}"}
return {"value": value}
Post-hooks
Post-hooks run after the LLM finishes. The framework auto-injects two special parameters if your tool accepts them:
output(str) — the LLM's final response text.tool_results(list) — every tool call made during the agent loop. Each entry is{"tool": name, "args": {...}, "result": ...}.
Just declare the parameters you need — the framework fills them in:
@tool
def send_slack_report(output: str, tool_results: list, channel: str) -> str:
"""Post the LLM report and any chart images to Slack."""
charts = [r["result"] for r in tool_results if r["result"].endswith(".png")]
post_to_slack(channel=channel, text=output, attachments=charts)
return f"sent to {channel} with {len(charts)} charts"
post_hook:
- slack.send_slack_report:
channel: "#alerts"
The channel comes from the YAML. The output and tool_results are injected by the framework.
You can filter tool_results however you want — by tool name, by result content, by args:
# Get all chart paths
charts = [r["result"] for r in tool_results if r["tool"].startswith("plot_")]
# Get results from a specific tool
summaries = [r["result"] for r in tool_results if r["tool"] == "analysis.get_summary"]
# Get all tool calls that used a specific argument
weekly = [r for r in tool_results if r["args"].get("days") == 7]
Multi-agent
Sub-agents can be called as tools. The parent agent passes a task string; the sub-agent runs its full loop and returns a string result.
from smalltask.runner import agent_tool, run_agent
from pathlib import Path
run_agent(
Path("agents/orchestrator.yaml"),
extra_tools={
"summarize": agent_tool(
name="summarize",
agent_path=Path("agents/summarize.yaml"),
description="Summarise a block of text. Pass it as 'task'.",
)
},
)
The orchestrator YAML lists summarize in its tools: section like any other tool.
Templates
smalltask init --list shows available starter templates:
| Template | Scaffolds |
|---|---|
default |
Generic stub tools + example agent |
github |
GitHub REST API tools + PR digest agent |
smalltask init --template github
LLM compatibility
smalltask uses prompt-based tool calling over raw HTTP — no SDK, no provider lock-in. It works with any OpenAI-compatible endpoint:
- OpenRouter — access any model via one API key
- Ollama — local models
- Groq
- Together AI
- Anthropic, OpenAI, Gemini via their OpenAI-compatible layers
- Any Bedrock / Azure endpoint with an OpenAI-compatible adapter
Contributing
git clone https://github.com/gabrielmoffa/smalltask
cd smalltask
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
Run the tests:
pytest tests/
The tests cover core logic (schema generation, tool loading, prompt parsing) without requiring a real LLM or API key. If you change loader.py or prompt_tools.py, run them before pushing.
License
MIT
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
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 smalltask-0.2.0.tar.gz.
File metadata
- Download URL: smalltask-0.2.0.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5edf79903364453b5741324ab9600f5d457ca85ba5241091ddee8d6566e159f0
|
|
| MD5 |
7b8f0201353eeff4f8202976ff02c1ed
|
|
| BLAKE2b-256 |
2da182cc6018558b5feb9f030d13ad2ed8d148d18337f923022a20576c83d1a7
|
Provenance
The following attestation bundles were made for smalltask-0.2.0.tar.gz:
Publisher:
publish.yml on gabrielmoffa/smalltask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smalltask-0.2.0.tar.gz -
Subject digest:
5edf79903364453b5741324ab9600f5d457ca85ba5241091ddee8d6566e159f0 - Sigstore transparency entry: 1281031756
- Sigstore integration time:
-
Permalink:
gabrielmoffa/smalltask@2ee09f61bf850fb3cdcae0cda72ed40d80a86ecd -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/gabrielmoffa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2ee09f61bf850fb3cdcae0cda72ed40d80a86ecd -
Trigger Event:
push
-
Statement type:
File details
Details for the file smalltask-0.2.0-py3-none-any.whl.
File metadata
- Download URL: smalltask-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.0 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 |
ab3929c884e0a68be1746af6c3594e0fdfffd00e29494c6194082207d16a8f90
|
|
| MD5 |
b84063a978d193b165bc3ac68ae607a4
|
|
| BLAKE2b-256 |
cac8405d4b3f6de8929572dc9a929ddd68ee035b2b58144371ea6e6dcbd59c53
|
Provenance
The following attestation bundles were made for smalltask-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on gabrielmoffa/smalltask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smalltask-0.2.0-py3-none-any.whl -
Subject digest:
ab3929c884e0a68be1746af6c3594e0fdfffd00e29494c6194082207d16a8f90 - Sigstore transparency entry: 1281031760
- Sigstore integration time:
-
Permalink:
gabrielmoffa/smalltask@2ee09f61bf850fb3cdcae0cda72ed40d80a86ecd -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/gabrielmoffa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2ee09f61bf850fb3cdcae0cda72ed40d80a86ecd -
Trigger Event:
push
-
Statement type: