Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

psi-agent

English

用 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/Telegram/Feishu) ── TCP/Unix/Named Pipe ── Session ── TCP/Unix/Named Pipe ── AI

快速开始

需要 Python >= 3.14

三个终端,三步跑起来:

# 安装
uv sync

# 终端 1:启动 AI 后端(--api-key 可选,不传则读 PSI_AI_API_KEY 环境变量)
uv run psi-agent ai \
  --provider openai \
  --session-socket ./ai.sock \
  --model gpt-4o-mini \
  --api-key $OPENAI_API_KEY \
  --base-url https://api.openai.com/v1

# 终端 2:启动 Session(--workspace 可选,默认当前目录)
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
├── run                       # 批量启动(psi-agent run config.yml)
├── ai                        # 统一 AI 后端(支持 50+ provider)
├── gateway                   # 生命周期管理 + REST API + Web Console
├── session                    # Session + workspace 管理
└── channel
    ├── repl                   # 交互式 REPL
    ├── cli                    # 单次消息
    ├── telegram               # Telegram bot
    └── feishu                 # 飞书 bot

定义你自己的 Agent

一个 workspace 就是一个 agent:

my-workspace/
├── tools/                    # 每个 .py 文件定义若干 tool(所有非 _ 的 async def)
│   └── 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 函数,文件中所有非 _ 开头的 async def 都会加载为 tool:

# 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

许可

MIT License. 详见 LICENSE。

Metadata

Release files for psi-agent 0.0.1a20260703

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psi-agent 0.0.1a20260703
File Size Uploaded Provenance Actions
psi_agent-0.0.1a20260703.tar.gz 7.1 MB With provenance Details for psi_agent-0.0.1a20260703.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for psi-agent 0.0.1a20260703
File Interpreter ABI Platform Actions
psi_agent-0.0.1a20260703-py3-none-any.whl Python 3 none any Details for psi_agent-0.0.1a20260703-py3-none-any.whl

Total release size: 13.5 MB

Release files / psi_agent-0.0.1a20260703.tar.gz

Download URL psi_agent-0.0.1a20260703.tar.gz
Size 7.1 MB
Tags Source
SHA-256 checksum
How to use checksums
4d9d8048e014d589ea5656021cdddf7ed019255619c1ea59f0b01901af9a006d
BLAKE2b-256 checksum
How to use checksums
2978f2ad56383df4895355108e229b24b46f6f11e092a9bec18b412f81c19686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / psi_agent-0.0.1a20260703-py3-none-any.whl

Download URL psi_agent-0.0.1a20260703-py3-none-any.whl
Size 6.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
cb3d61c73dab20d562da4f1db67c337c184c72ee419a21801aea3942b7acf359
BLAKE2b-256 checksum
How to use checksums
466d56800c20a9028553bdb5c7ceaaa1cab82066f5ccfbcc5009ea0f6553d64d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Security for psi-agent 0.0.1a20260703

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for psi_agent-0.0.1a20260703.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page