Skip to content

ninehills/DeepWriter

Repository files navigation

DeepWriter

基于多智能体架构的通用深度写作智能体

快速开始

1. 列出可用的 Agent

# 查看所有可用的 Agent
python agent.py list agent

# 输出示例:
# Available Agents
# ┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Name             ┃ Description                    ┃ Path               ┃ Examples             ┃
# ┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
# │ PatentDraftAgent │ 根据输入的专利参考文件,       │ PatentDraftAgent   │ 根据 ./data/...      │
# │                  │ 编写专利交底书                 │                    │ 编写专利交底书        │
# │ PatentWriterAgent│ 根据输入的专利参考文件,       │ PatentWriterAgent  │ 根据 ./data/...      │
# │                  │ 编写专利提案                   │                    │ 编写专利提案          │
# └──────────────────┴────────────────────────────────┴────────────────────┴──────────────────────┘

2. 运行 Agent 生成专利交底书

# 运行专利交底书生成 Agent
python agent.py run PatentDraftAgent -p "根据 ./data/example_input.md 编写专利交底书"

# 系统会显示:
# ┏━━━━━━━━━━━━━━━ Starting New Agent Session ━━━━━━━━━━━━━━━┓
# ┃ Agent: PatentDraftAgent                                   ┃
# ┃ Session ID: a8a1375f-771f-4b32-8e52-c4316fba5d95         ┃
# ┃ Prompt: 根据 ./data/example_input.md 编写专利交底书        ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#
# ┏━━━━━━━━━━━━━━━ Session Information ━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Our Session ID: a8a1375f-771f-4b32-8e52-c4316fba5d95     ┃
# ┃ Agent Session ID: 39305c2f-1e30-4f7c-b090-71685ade5610   ┃
# ┃ Model: glm-4.6                                           ┃
# ┃ Working Directory: /path/to/PatentDraftAgent             ┃
# ┃ Agent: PatentDraftAgent                                  ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#
# Agent 会自动:
# 1. 读取输入文件
# 2. 调用多个子代理(title-generator, patent-searcher, etc.)
# 3. 生成完整的专利交底书
# 4. 保存到 output/temp_[uuid]/04_final/output.md

3. 查看所有会话

# 列出所有运行过的会话
python agent.py list session

# 输出示例:
# Sessions
# ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓
# ┃ Session ID ┃ Agent            ┃ Status    ┃ Created            ┃ Messages ┃ Cost   ┃
# ┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━┩
# │ a8a1375f...│ PatentDraftAgent │ completed │ 2025-10-29 15:47:43│ 42       │ $0.25  │
# │ f83f775b...│ PatentWriterAgent│ running   │ 2025-10-29 14:20:15│ 18       │ $0.12  │
# └────────────┴──────────────────┴───────────┴────────────────────┴──────────┴────────┘

4. 查看会话详情

# 查看特定会话的详细信息和消息历史
python agent.py show -s a8a1375f-771f-4b32-8e52-c4316fba5d95

# 输出包括:
# - 会话元数据(Session ID, Agent, Status, Cost, etc.)
# - 完整的消息历史(Claude 的响应、工具调用、结果等)

5. 恢复会话继续对话

# 恢复之前的会话,继续对话
python agent.py resume -s a8a1375f-771f-4b32-8e52-c4316fba5d95 -p "请补充更多实施例"

# 系统会:
# 1. 加载之前的完整对话历史
# 2. 继续与 Agent 对话
# 3. 保持上下文连贯性

会话管理说明

  • Session ID: 每个会话有唯一的 UUID 标识
  • 自动保存: 所有消息和统计信息自动保存到 logs/<session_id>/
  • 上下文保持: resume 命令会完整恢复对话历史
  • 双 ID 系统:
    • Our Session ID: 我们的会话标识(用于日志管理)
    • Agent Session ID: Claude SDK 的会话标识(用于恢复对话)

环境依赖

# node (npm/npx)
# Claude Code
npm install -g @anthropic-ai/claude-code  
# python
pip install -r requirements.txt

通用架构

不同的智能体在不同的子目录下,尝试用一套智能体解决,失败了,过于复杂。如下架构仅供参考,不同的 Agent有不同的架构。

graph TB
    %% 用户界面
    subgraph UserInterface["用户界面"]
        direction LR
        WebUI["🌐 Web 应用<br/>上传参考资料"]
        CLI["💻 CLI 应用<br/>命令行模式"]
    end

    %% 用户请求
    UserRequest["📄 用户请求<br/>生成专利申请文件"]

    %% 多智能体系统
    subgraph MultiAgent["文档写作多智能体系统"]
        direction TB

        %% 主智能体
        LeadAgent["<b>主智能体 Lead Agent</b><br/>(项目协调器)<br/><br/><b>工具集</b>: File I/O + Markitdown + MCP Tools + run_subagent + complete_task + Todolist"]

        %% 子智能体
        subgraph Subagents["子智能体"]
            direction LR
            S1["📄 文档解析<br/>Input Parser"]
            S2["🔍 信息检索<br/>Information Retriever"]
            S3["📋 大纲生成<br/>Outline Generator"]
            S4["✍️ 段落撰写<br/>Content Writer"]
            S5["📊 图表生成<br/>Diagram Generator"]
            S6["📦 文档整合和转换<br/>Document Merger"]
        end

        %% 文件系统
        Memory["💾 文件系统<br/>Memory<br/>output/temp_UUID/"]

        %% TODO管理
        TodoList["📝 TodoList<br/>任务管理"]
    end

    %% MCP工具层
    subgraph MCPTools["MCP 工具服务器"]
        direction LR
        GooglePatents["🔍 Google Patents<br/>专利检索"]
        ExaSearch["🌐 Exa Search<br/>Web搜索"]
        Markitdown["📝 Markitdown<br/>文档转换"]
        ImageGenerator["🖼️ 图片生成<br/>Image Generator"]
        DocumentGenerator["📄 文档生成<br/>Document Generator"]
    end

    %% 连接关系
    UserInterface -->|用户请求| UserRequest
    UserRequest --> LeadAgent

    LeadAgent <--> S1
    LeadAgent <--> S2
    LeadAgent <--> S3
    LeadAgent <--> S4
    LeadAgent <--> S5
    LeadAgent <--> S6

    LeadAgent <-->|读写| Memory
    LeadAgent <-->|维护| TodoList

    S1 -.调用.-> Markitdown
    S2 -.调用.-> GooglePatents
    S2 -.调用.-> ExaSearch
    S5 -.调用.-> ImageGenerator
    S6 -.调用.-> DocumentGenerator

    LeadAgent -->|最终专利文件| FinalOutput["📑 完整专利申请文件"]

    subgraph Skills["技能集"]
        direction LR
        PatentSkills["🔧 专利写作技能"]
        DiagramSkills["📊 图表生成技能"]
        PatentOutline["📑 专利大纲模版"]
    end

    PatentSkills -->|加载技能| LeadAgent
    DiagramSkills -->|加载技能| LeadAgent
    PatentOutline -->|加载技能| LeadAgent



    %% 样式定义
    style LeadAgent fill:#B3D4E8,stroke:#666,stroke-width:2px,color:#333
    style S1 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style S2 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style S3 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style S4 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style S5 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style S6 fill:#D4E8F0,stroke:#666,stroke-width:1px,color:#333
    style Memory fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333
    style GooglePatents fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333
    style ExaSearch fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333
    style Markitdown fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333
    style DocumentGenerator fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333
    style ImageGenerator fill:#E8E8E8,stroke:#666,stroke-width:1px,color:#333

    style UserInterface fill:#F5F5F5,stroke:#999,stroke-width:1px
    style MultiAgent fill:#F5F5F5,stroke:#999,stroke-width:2px
    style MCPTools fill:#F5F5F5,stroke:#999,stroke-width:1px
    style Subagents fill:#FAFAFA,stroke:#CCC,stroke-width:1px
    style UserRequest fill:#FFF,stroke:#999,stroke-width:1px,color:#333
    style FinalOutput fill:#FFF,stroke:#999,stroke-width:1px,color:#333
Loading

About

基于多智能体架构的深度写作智能体

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors