timczm/tinyagent
关于
The core agent loop in a small Python codebase
开发工具可以做什么
- One runtime, two interfaces: the CLI and Python SDK share the same async agent runtime.
- Provider flexibility: use DeepSeek out of the box or configure another OpenAI-compatible Chat Completions endpoint.
- Persistent work: sessions and complete message history are stored in SQLite outside the workspace.
- Workspace-aware tools: read, write, patch, list, and execute commands within a validated workspace boundary.
实测星标增长
- 24小时
- 0
- 7天
- -2
- 15天
- -4
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.zh-Hans.md
原文English | 简体中文
tinyagent 是一个面向单个可信用户、单实例运行的轻量 Python Agent。当前版本为支持命令行与进程内 Python SDK、DeepSeek 和自定义 OpenAI-compatible Provider、持久 Session、Workspace 工具、分层 Memory、MCP,以及渐进加载的 Skills。
项目要求 Python 3.11 或更高版本,当前优先支持 Linux。
源码安装
先安装 uv,然后在本仓库中安装依赖并初始化当前 Workspace:
cd tinyagent
uv sync
uv run tinyagent init
init 会创建 .tinyagent/config.toml、.tinyagent/workspace-id 和空的 skills/ 目录。API key 应通过配置指定的环境变量提供,不要写进配置文件:
export DEEPSEEK_API_KEY="你的密钥"
Linux 上的命令执行默认依赖 Bubblewrap。系统尚未安装或无法使用时,可让 tinyagent 检测系统、展示安装命令并在确认后安装:
uv run tinyagent sandbox install
最后运行诊断,确认配置、状态存储、Memory、MCP 和命令沙箱可用:
uv run tinyagent doctor
使用教程
1. 完成第一次对话
单轮运行:
uv run tinyagent run "你好,请用一句话介绍你自己"
进入交互式对话,并指定进入哪个本地目录:
uv run tinyagent chat --workspace /tmp/tinyagent-test
Chat 支持以下命令:
/new [name] 新建并切换到 Session
/sessions 列出当前 Workspace 的 Session
/resume <id|name> 切换到已有 Session
/help 显示帮助
/exit 退出 Chat
按 Enter 发送消息,按 Ctrl-J 或 Alt-Enter 插入换行,按 Ctrl-D 退出。输入 / 后可按 Tab 补全命令。
2. 配置 Provider 和工具
默认配置文件位于 Workspace 的 .tinyagent/config.toml。下面是一个常用配置示例:
[agent]
provider = "deepseek"
model = "deepseek-v4-flash"
context_window_tokens = 64000
max_tool_iterations = 50
max_tool_output_chars = 20000
[providers.deepseek]
base_url = "https://api.deepseek.com"
api_key_env = "DEEPSEEK_API_KEY"
request_timeout_seconds = 120
stream_idle_timeout_seconds = 30
max_retries = 2
retry_base_delay_seconds = 0.25
[tools]
enabled = true
read_only = false
allow_unsafe_exec = false
exec_network_access = true
max_file_bytes = 1048576
max_list_entries = 1000
exec_timeout_seconds = 60
max_exec_output_chars = 20000
[memory]
enabled = true
max_chars = 6000
curator_event_threshold = 10
[mcp]
使用自定义 OpenAI-compatible 服务时,新增一个 Provider 配置段,并把 agent.provider 改为对应名称。tinyagent 当前使用 Chat Completions API。
只读运行可配置为:
[tools]
read_only = true
完全关闭内置 Workspace 工具可设置 enabled = false。只有明确接受无进程级文件系统隔离的风险时,才应设置 allow_unsafe_exec = true。
3. 管理 Session
uv run tinyagent sessions new project-a
uv run tinyagent sessions list
uv run tinyagent sessions resume project-a
uv run tinyagent run "继续刚才的话题"
uv run tinyagent sessions delete project-a
也可以为某次运行显式指定 Session:
uv run tinyagent run "记住数字 17" --session-id project-a
uv run tinyagent chat --session-id project-a
4. 使用 Memory
uv run tinyagent memory show
uv run tinyagent memory sync
uv run tinyagent memory history --limit 20
uv run tinyagent memory restore 3
长期记忆保存在当前 Workspace 的 .tinyagent/memory/MEMORY.md。手工修改后,运行 memory sync 记录新修订。
5. 连接 MCP Server
远程 Streamable HTTP Server 示例:
[mcp.servers.openai_docs]
transport = "streamable_http"
url = "https://developers.openai.com/mcp"
enabled_tools = ["search_openai_docs", "fetch_openai_doc"] # optional
connect_timeout_seconds = 30
tool_timeout_seconds = 60
allow_parallel_calls = false
本地 stdio Server 示例:
[mcp.servers.local_index]
transport = "stdio"
command = "uvx"
args = ["local-index-mcp"]
cwd = "."
env = { CHILD_TOKEN = "LOCAL_INDEX_TOKEN" }
enabled_tools = ["*"]
env 和 headers_from_env 的值都是来源环境变量名,不是凭证本身。配置完成后运行 uv run tinyagent doctor 检查连接和已发现的工具。
6. 使用 Skills
Workspace Skill 位于 skills/<name>/SKILL.md。例如:
---
name: release-notes
description: Produce concise release notes from the current changes.
---
# Release notes
Summarize user-visible behavior, compatibility changes, and verification.
检查和查看 Skill:
uv run tinyagent skills list
uv run tinyagent skills validate
uv run tinyagent skills show release-notes
模型可按需读取相关 Skill;也可以在提示词中显式引用:
请用 $release-notes 整理这次发布。
运行方式
命令行
源码环境中使用 uv run:
uv run tinyagent run "你好"
uv run tinyagent chat
安装生成的命令可直接运行:
tinyagent run "你好"
tinyagent chat
通过 --workspace 指定其他 Workspace:
tinyagent doctor --workspace /path/to/workspace
tinyagent run "总结当前项目" --workspace /path/to/workspace
异步 Python SDK
异步接口是核心实现:
import asyncio
from tinyagent import AsyncTinyAgent
async def main() -> None:
async with AsyncTinyAgent.from_config(workspace=".") as agent:
session = await agent.sessions.new("demo")
result = await agent.run("你好", session_id=session.id)
print(result.content)
asyncio.run(main())
流式输出:
async with AsyncTinyAgent.from_config(workspace=".") as agent:
async for event in agent.stream("介绍一下这个项目"):
if event.type == "text.delta":
print(event.delta or "", end="", flush=True)
同步 Python SDK
from tinyagent import TinyAgent
with TinyAgent.from_config(workspace=".") as agent:
result = agent.run("你好")
print(result.content)
示例与开发检查
各版本的可运行示例位于 examples/:
uv run python examples/v0_7_demo.py
开发检查不需要真实 Provider 凭证:
uv run ruff check src tests
uv run basedpyright
uv run pytest
开发者贡献指南
各模块的目标、方向与边界分别记录在:
探索相关项目
加载中…