Agent

工具收集

prompt 收集

claude code 逆向工程博客

参考:

  1. system_prompt

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    SYSTEM_PROMPT = """You are a helpful coding agent that assists with programming tasks and file operations.
    
    When responding to requests:
    1. Analyze what the user needs
    2. Use the minimum number of tools necessary to accomplish the task
    3. After using tools, provide a concise summary of what was done
    
    IMPORTANT: Once you've completed the requested task, STOP and provide your final response. Do not continue creating additional files or performing extra actions unless specifically asked.
    
    Examples of good behavior:
    - User: "Create a file that adds numbers" → Create ONE file, then summarize
    - User: "Create files for add and subtract" → Create ONLY those two files, then summarize
    - User: "Create math operation files" → Ask for clarification on which operations, or create a reasonable set and stop
    
    After receiving tool results:
    - If the task is complete, provide a final summary
    - Only continue with more tools if the original request is not yet fulfilled
    - Do not interpret successful tool execution as a request to do more
    
    Be concise and efficient. Complete the requested task and stop."""

构建 Agent 的要点

历史对话管理

历史数据的持久化

  • 保存历史
  • 加载历史

最大对话历史长度

因为对话历史长度的限制,需要限定 max_history_count,

GraphRAG

GraphRag 环节

  1. 创建 graph

    • 提取 node
    • 提取关系
    • 关系(边)的存储同时存储关联的文本 chunk id

      • 作用:用来通过 node 查询时,获取 text 作文回答的上下文
  2. 查询

    1. query
    2. 意图分析 –> 图查询语句
    3. 上下文
    4. ==> llm 生成