graph TB
    subgraph "① 消息接收"
        MSG[用户消息<br/>Telegram/Slack/...]
        SDK[平台 SDK<br/>原生协议接收]
        NORM[消息标准化<br/>统一格式]
    end

    subgraph "② 路由决策"
        RT[Route Resolver<br/>channel + peer → agentId]
        BIND[Session Binding<br/>会话绑定服务]
        SK[Session Key<br/>生成会话键]
    end

    subgraph "③ 会话管理"
        ACP[ACP Session Manager]
        LOCK[Session Write Lock<br/>防并发写入]
        LOAD[加载会话历史<br/>JSONL 转录]
    end

    subgraph "④ Agent 推理"
        PI[Pi Agent Runner]
        LLM[LLM API 调用<br/>含 Thinking Mode]
        TOOL[工具调用<br/>审批 → 执行]
        MEM[记忆检索<br/>混合搜索]
    end

    subgraph "⑤ 响应投递"
        STREAM[流式响应<br/>逐 Token 返回]
        TRANS[格式转换<br/>适配目标平台]
        DELIVER[投递到通道<br/>支持线程/回复]
        PERSIST[持久化<br/>会话 + 记忆写入]
    end

    MSG --> SDK --> NORM
    NORM --> RT --> BIND --> SK
    SK --> ACP --> LOCK --> LOAD
    LOAD --> PI --> LLM
    LLM --> TOOL
    TOOL --> MEM
    LLM --> STREAM --> TRANS --> DELIVER
    DELIVER --> PERSIST

    style MSG fill:#9B59B6,color:#fff
    style PI fill:#E74C3C,color:#fff
    style DELIVER fill:#2ECC71,color:#fff