A microkernel-style agent framework
Project description
psi-agent
用 Python socket 拼装 AI agent 的微框架。
你只需要写 Python 函数和 Markdown——剩下的 socket 通信、tool calling、SSE 流式、定时任务框架全替你做了。
为什么选它
- 简单组合:ai、session、channel 三个独立进程,socket 对插即用。没有中心配置,不依赖数据库
- Workspace 即 Agent:在
workspace/下丢几个 Python 函数就是 tools,写个 system prompt 就是 agent 人格,加个 cron 就是定时任务 - 流式交互:REPL 实时显示 AI 思考过程(dim 样式)和最终回复,所见即所得
架构
用户 ←→ Channel (REPL/CLI) ──Unix socket── Session ──Unix socket── AI (OpenAI/Anthropic)
快速开始
需要 Python >= 3.14
三个终端,三步跑起来:
# 安装
uv sync
# 终端 1:启动 AI 后端(--api-key 可选,不传则读 OPENAI_API_KEY 环境变量)
uv run psi-agent ai openai-completions \
--session-socket ./ai.sock \
--model gpt-4o-mini \
--api-key $OPENAI_API_KEY \
--base-url https://api.openai.com/v1
# 终端 2:启动 Session
uv run psi-agent session \
--workspace ./examples/a-simple-bash-only-workspace \
--channel-socket ./channel.sock \
--ai-socket ./ai.sock
# 终端 3:REPL 交互
uv run psi-agent channel repl --session-socket ./channel.sock
REPL 操作:Enter 换行,Alt+Enter 发送,Ctrl+D 退出。
也可以一句命令搞定:
uv run psi-agent channel cli \
--session-socket ./channel.sock \
--message "列出当前目录的文件"
CLI 一览
psi-agent
├── ai
│ ├── openai-completions # OpenAI 兼容透传
│ └── anthropic-messages # Anthropic→OpenAI 转换
├── session # Session + workspace 管理
└── channel
├── repl # 交互式 REPL
└── cli # 单次消息
定义你自己的 Agent
一个 workspace 就是一个 agent:
my-workspace/
├── tools/ # 每个 .py 文件定义一个 tool
│ └── bash.py # async def bash(command: str) -> str
├── skills/ # */SKILL.md 技能文档(system_prompt_builder 自行遍历)
├── schedules/ # 定时任务
│ └── daily-report/
│ └── TASK.md # YAML 头 (name, cron) + Markdown body
└── systems/
└── system.py # async def system_prompt_builder() -> str
Tool 就是一个 async 函数,函数名 = 文件名,参数类型自动映射为 JSON Schema:
# tools/bash.py
import anyio
async def bash(command: str) -> str:
"""Execute a bash command.
Args:
command: The command to run.
"""
result = await anyio.run_process(["/bin/bash", "-c", command])
return result.stdout.decode().strip()
定时任务的 body 会在 cron 触发时作为消息发送给 AI:
---
name: daily-report
cron: "0 12 * * *"
---
请生成一份项目进展日报。
更多细节见 examples/a-simple-bash-only-workspace/。
开发
uv run ruff check . # lint
uv run ruff format --check . # 格式
uv run ty check # 类型
uv run pytest -v # 测试
作者
Hao Zhang hzhangxyz@outlook.com
许可
GNU Affero General Public License v3.0 or later. 详见 LICENSE。
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 psi_agent-0.0.1a20260524.tar.gz.
File metadata
- Download URL: psi_agent-0.0.1a20260524.tar.gz
- Upload date:
- Size: 104.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5ae79e7b791b7eadd15869197fdd4c6f115686959cb7de582cf1f3b047bb88b
|
|
| MD5 |
1d73fc6312e8ed014a0bc0bc9045dbce
|
|
| BLAKE2b-256 |
279f8f74cda311fa5fad78f754ac08dbb4cc9a7ac6801c87fc8b80b722844d50
|
Provenance
The following attestation bundles were made for psi_agent-0.0.1a20260524.tar.gz:
Publisher:
auto-alpha-tag.yml on psi-agent/psi-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psi_agent-0.0.1a20260524.tar.gz -
Subject digest:
a5ae79e7b791b7eadd15869197fdd4c6f115686959cb7de582cf1f3b047bb88b - Sigstore transparency entry: 1616588356
- Sigstore integration time:
-
Permalink:
psi-agent/psi-agent@71f6dcc2f502b9eddb3d1726b43bce8dcd68fe8d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/psi-agent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto-alpha-tag.yml@71f6dcc2f502b9eddb3d1726b43bce8dcd68fe8d -
Trigger Event:
schedule
-
Statement type:
File details
Details for the file psi_agent-0.0.1a20260524-py3-none-any.whl.
File metadata
- Download URL: psi_agent-0.0.1a20260524-py3-none-any.whl
- Upload date:
- Size: 36.6 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 |
5f948af22ed01734a09932be6615d7adb1efa610027cfc0410b004eebfe0d83d
|
|
| MD5 |
71b807bc77c04fd09950fa86c2c4cb4f
|
|
| BLAKE2b-256 |
89543eda64c5ea1c33a53afed5adc501f9a5a5e126d0f3c30bc8e03863893204
|
Provenance
The following attestation bundles were made for psi_agent-0.0.1a20260524-py3-none-any.whl:
Publisher:
auto-alpha-tag.yml on psi-agent/psi-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psi_agent-0.0.1a20260524-py3-none-any.whl -
Subject digest:
5f948af22ed01734a09932be6615d7adb1efa610027cfc0410b004eebfe0d83d - Sigstore transparency entry: 1616588442
- Sigstore integration time:
-
Permalink:
psi-agent/psi-agent@71f6dcc2f502b9eddb3d1726b43bce8dcd68fe8d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/psi-agent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto-alpha-tag.yml@71f6dcc2f502b9eddb3d1726b43bce8dcd68fe8d -
Trigger Event:
schedule
-
Statement type: