Skip to content

Clay-HHK/CompanyAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CompanyAgent

基于公司组织架构隐喻的多 Agent 协作框架。

CompanyAgent 用真实公司的组织架构(Gateway、TeamLead、Planner、Researcher、Executor、Reviewer)建模多 Agent 协作系统。框架领域无关,通过配置适配不同业务场景。

特性

  • 三层决策路由 — Gateway 自动分类任务复杂度,路由到 Direct / Chain / DAG 三种执行模式
  • DAG 并行编排 — Planner 将复杂任务分解为依赖图,Coordinator 编排并行执行
  • 多 LLM 支持 — 每个 Agent 可配置不同模型(Claude、GPT、DeepSeek、Kimi、GLM、Ollama 等)
  • 事件驱动通信 — 基于 pub/sub 的 EventBus,可插拔 asyncio / Redis 后端
  • 三层记忆系统 — Private → Team → Global 分层记忆,自动去重与淘汰
  • 经验反馈闭环 — PostMortem 复盘 → Experience 记忆 → RuleBook 规则沉淀
  • Web UI — React + WebSocket 实时可视化 DAG 执行过程
  • 完全可扩展 — 所有基础设施使用抽象接口 + 可插拔后端

架构

用户输入 → Gateway(分类)
            ├─ Tier 1: Executor 直接执行 (简单任务)
            ├─ Tier 2: TeamLead → Researcher → Executor → Reviewer (中等任务)
            └─ Tier 3: Planner → TaskGraph → Coordinator 并行编排 (复杂任务)

角色体系

核心角色 职责
Gateway 任务分类与路由
TeamLead 中等任务独立处理,必要时上报
Planner 复杂任务分解为 DAG
Researcher 信息收集与调研
Executor 执行具体任务
Reviewer 质量审查(PASS / REVISE / REPLAN)

可选角色:Coordinator、Architect、Archivist、Accountant、Security、Observer

快速开始

安装

pip install -e ".[dev]"

# 如需 Web UI
pip install -e ".[web]"

运行示例(无需 API Key)

python examples/simple_task.py

使用真实 LLM

import asyncio
from companyagent.config.profile import ModelConfig, Profile, RoleConfig
from companyagent.core.engine import Engine

async def main():
    profile = Profile(
        name="my-team",
        roles={
            "Gateway": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
            "Planner": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
            "Researcher": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
            "Executor": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
            "Reviewer": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
        },
    )

    engine = Engine.from_profile(
        profile=profile,
        credentials={"anthropic": "your-api-key"},
    )

    result = await engine.run("分析当前 AI Agent 框架的技术趋势并给出建议")
    print(f"成功: {result.success}")
    print(f"输出: {result.output}")

asyncio.run(main())

混合模型配置

不同 Agent 可以使用不同的 LLM,优化成本与效果:

profile = Profile(
    name="mixed-models",
    roles={
        "Gateway": RoleConfig(enabled=True, model=ModelConfig(provider="deepseek", model="deepseek-chat")),
        "Planner": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-sonnet-4-6")),
        "Executor": RoleConfig(enabled=True, model=ModelConfig(provider="deepseek", model="deepseek-chat")),
        "Reviewer": RoleConfig(enabled=True, model=ModelConfig(provider="anthropic", model="claude-haiku-4-5-20251001")),
    },
)

CLI

# 运行任务
python -m companyagent "你的任务描述"

# 运行测试
pytest tests/

项目结构

companyagent/
├── core/           # Engine, Workflow, Task 模型
├── agents/         # 12 种 Agent 角色实现
├── communication/  # EventBus 及后端 (asyncio / Redis)
├── memory/         # 三层记忆系统及后端
├── llm/            # LLM Provider 抽象层
├── tools/          # 工具注册, MCP 适配, Skill 加载
├── review/         # 复盘, 经验反馈, 规则库
├── config/         # 配置管理, Profile
└── interfaces/     # CLI + Web UI (FastAPI + React)

支持的 LLM

Provider 模型
Anthropic Claude Opus / Sonnet / Haiku
OpenAI GPT-4o / GPT-4 / GPT-3.5
DeepSeek deepseek-chat / deepseek-reasoner
Kimi moonshot-v1-*
GLM glm-4 / glm-3-turbo
Ollama 本地部署的任意模型

所有 OpenAI 兼容的 API 均可通过 base_url 配置接入。

开发

# 代码检查
ruff check . && ruff format --check .

# 类型检查
mypy companyagent/

# 运行测试
pytest tests/

License

Apache License 2.0

About

Multi-agent collaboration framework modeled after company organizational structures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors