Skip to main content

Psi Agent Platform - portable, composable AI agents

Project description

Psi Agent Platform

一个绿色可移植、组件化的 AI Agent 平台。

特性

  • 绿色可移植: 一个 workspace 目录包含完整的 agent(提示词、工具、技能)
  • 组件化: 四个独立进程通过 Unix socket 通信
  • Let it crash: 除了网络故障,所有错误都应该让进程 crash
  • 不考虑兼容性: 目前是第一版,不需要向后兼容

架构

┌─────────────┐     socket      ┌─────────────┐     socket      ┌─────────────┐
│ psi-channel │ ─────────────── │ psi-session │ ─────────────── │   psi-ai    │
│     (TUI)   │                 │  (ReAct)    │                 │  (LLM API)  │
└─────────────┘                 └─────────────┘                 └─────────────┘
                                        │
                                        ▼
                                ┌─────────────┐
                                │  workspace  │
                                │ (tools/skills)
                                └─────────────┘

Socket 命名约定:

  • 代码变量:session_socket, channel_socket, ai_socket
  • 文件命名:ai.sock, channel.sock

安装

uv sync

开发依赖:

uv sync --all-extras

开发

本仓库使用 ruff (lint/格式化) 和 ty (类型检查) 进行代码质量控制。

Lint 检查:

uv run ruff check examples/ tests/ src/

格式检查:

uv run ruff format examples/ tests/ src/ --check

类型检查:

uv run ty check examples/ tests/ src/

运行测试:

# 单元测试
uv run pytest tests/unit/ -v

# 集成测试(需要设置环境变量)
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://api.openai.com/v1"
export OPENAI_MODEL="gpt-4o-mini"
uv run pytest tests/integration/ -v

CI/CD: GitHub Actions 自动运行 lint、类型检查和单元测试。集成测试需要配置 GitHub Secrets(OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL)。

快速开始

终端 1 - 启动 LLM Caller:

uv run psi-ai-openai --session-socket ./ai.sock \
    --model gpt-4o \
    --api-key $API_KEY \
    --base-url https://api.openai.com/v1

终端 2 - 启动 Session:

# 默认:自动生成 session_id,无历史记录
uv run psi-session --workspace ./examples/simple_example \
    --channel-socket ./channel.sock \
    --ai-socket ./ai.sock

# 指定 session_id:继续历史记录
uv run psi-session --workspace ./examples/simple_example \
    --channel-socket ./channel.sock \
    --ai-socket ./ai.sock \
    --session-id main

终端 3 - 启动 TUI:

uv run psi-channel-tui --session-socket ./channel.sock

模块

模块 说明 Python API
psi-ai-openai LLM Caller(OpenAI 兼容) run_ai()
psi-session ReAct 循环引擎 run_session()
psi-channel-tui TUI 用户界面 run_channel()
psi-workspace-create 从目录创建 SquashFS run_create()
psi-workspace-mount 挂载 SquashFS 为 workspace(无需 root) run_mount()
psi-workspace-umount 卸载 workspace(无需 root) run_umount()
psi-workspace-snapshot 创建快照 run_snapshot()

Workspace 依赖(Ubuntu/Debian):

sudo apt install squashfuse fuse-overlayfs squashfs-tools

所有 CLI 使用 tyro 实现,支持 --log-level 参数控制日志输出。TUI 默认 WARNING 级别避免干扰界面。

Python API

可以直接在 Python 代码中使用:

import asyncio
from psi_agent.session import run_session
from psi_agent.ai.openai import run_ai
from psi_agent.workspace import run_create, run_mount, run_umount, run_snapshot

async def main():
    # 创建初始 squashfs
    await run_create("./examples/simple_example", "base.sqfs", tag="base")
    
    # 挂载
    await run_mount("base.sqfs", "./workspace")
    
    # 修改 workspace...
    
    # 创建快照
    await run_snapshot("./workspace", "v2.sqfs", tag="v1")
    
    # 卸载
    await run_umount("./workspace")
    
asyncio.run(main())

Workspace 结构

workspace/
├── AGENT.md           # 身份描述
├── tools/*.py         # 工具(导出 async run(params, workspace_path))
├── skills/*/SKILL.md  # 技能
└── systems/builder.py # 系统提示词构造器

文档

License

AGPLv3

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

psi_agent-0.0.1a5.tar.gz (100.1 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.1a5-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psi_agent-0.0.1a5.tar.gz
  • Upload date:
  • Size: 100.1 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.1a5.tar.gz
Algorithm Hash digest
SHA256 9ea191297dcac97f1d10faf0addb3cd985728dd7c6afa842e0ba3b66de6946e7
MD5 df375ccd53b4912f473b5a1392ad3745
BLAKE2b-256 f33c33a517e70f6b7ab547f9d1afc7b7505a4e708936149921e3f38724a2612a

See more details on using hashes here.

Provenance

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

Publisher: ci.yml on hzhangxyz/psi

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.1a5-py3-none-any.whl.

File metadata

  • Download URL: psi_agent-0.0.1a5-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for psi_agent-0.0.1a5-py3-none-any.whl
Algorithm Hash digest
SHA256 2396dce6308a56a46cfc478d2282cee267c27ffb5ad855357cd9bb9c893cd4f8
MD5 1003ab8d06633147fad2b9fe01611424
BLAKE2b-256 630d1c8dbba22babe69655ba7e83b0da6f7a7ae917e20b9b3bb8b11ae1c4d1ec

See more details on using hashes here.

Provenance

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

Publisher: ci.yml on hzhangxyz/psi

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