Skip to main content

A microkernel-style agent framework

Project description

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) ── 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
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                        # 统一 AI 后端(支持 50+ provider)
├── session                    # Session + workspace 管理
└── channel
    ├── repl                   # 交互式 REPL
    └── cli                    # 单次消息

定义你自己的 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

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

psi_agent-0.0.1a20260626.tar.gz (129.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psi_agent-0.0.1a20260626-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file psi_agent-0.0.1a20260626.tar.gz.

File metadata

  • Download URL: psi_agent-0.0.1a20260626.tar.gz
  • Upload date:
  • Size: 129.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for psi_agent-0.0.1a20260626.tar.gz
Algorithm Hash digest
SHA256 5c21a3f3e8c8eb3fcc1c4db7a176576f7cf277b0c16b192cd8ba879c80826a22
MD5 bef2087bb0b8a157a58b5f086162cd95
BLAKE2b-256 779ec4f7953f308603ce889086983be1db7e081aa175c7d4757238b4476a854d

See more details on using hashes here.

Provenance

The following attestation bundles were made for psi_agent-0.0.1a20260626.tar.gz:

Publisher: auto-alpha-tag.yml on genuineknowledge/psi-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psi_agent-0.0.1a20260626-py3-none-any.whl.

File metadata

File hashes

Hashes for psi_agent-0.0.1a20260626-py3-none-any.whl
Algorithm Hash digest
SHA256 719e8ab82ecc56c9e0bcc4ae280d36a3db97890dc06d80eddf3a5371d3063b3f
MD5 5b3b3e37ef1c2a31f7da6fe51764cc62
BLAKE2b-256 1f00b42c514d22cf496c466e4bcbd0a0e9a41b584aa5d5f5f4d7e22dcd4f8938

See more details on using hashes here.

Provenance

The following attestation bundles were made for psi_agent-0.0.1a20260626-py3-none-any.whl:

Publisher: auto-alpha-tag.yml on genuineknowledge/psi-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page