# intelliagent **Repository Path**: nbeta/intelliagent ## Basic Information - **Project Name**: intelliagent - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-20 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Custom Agent Framework 从零实现的自定义Agent框架,不依赖任何现有Agent开源框架,基于Python实现,通过HTTP API调用Anthropic Claude LLM。 ## 功能特性 - ✅ **MCP工具调用能力**:支持工具注册、LLM自动调用工具、结果回传 - ✅ **Skill能力**:支持可复用技能的创建、注册和调用 - ✅ **长短期记忆功能**:短期记忆保存会话上下文,长期记忆支持持久化存储 - ✅ **反思优化能力**:支持多种反思策略(CoT思维链、ReAct、自我反思) - ✅ **上下文自动压缩**:当上下文过长时自动压缩,保留关键信息 - ✅ **单会话模式**:轻量化实现,无需多会话管理 ## 项目结构 ``` agent/ ├── pyproject.toml # 项目配置、依赖管理 ├── .env.example # 环境变量示例 ├── AGENT.md # 智能体定义文档:角色、能力、规则 ├── MEMORY.md # 智能体持久化记忆文档 ├── llm/ # LLM对接模块 │ └── claude_client.py # Claude HTTP API客户端 ├── memory/ # 记忆模块 │ ├── short_term.py # 短期记忆(会话上下文) │ ├── long_term.py # 长期记忆(持久化存储) │ └── compressor.py # 上下文压缩器 ├── tools/ # MCP工具模块 │ ├── base.py # 工具基类定义 │ └── registry.py # 工具注册中心 ├── skills/ # 技能模块 │ ├── base.py # 技能基类定义 │ └── registry.py # 技能注册中心 ├── reflection/ # 反思优化模块 │ ├── base.py # 反思策略基类 │ ├── cot.py # 思维链(Chain of Thought)策略 │ ├── react.py # ReAct推理策略 │ └── self_reflection.py # 自我反思修正策略 ├── core/ # 核心调度模块 │ ├── agent.py # Agent主逻辑调度 │ └── config.py # 全局配置管理 ├── utils/ # 工具函数模块 │ ├── logger.py # 日志系统配置 │ └── common.py # 通用工具函数 ├── tests/ # 单元测试 └── examples/ # 示例代码 └── demo.py # 运行示例 ``` ## 快速开始 ### 1. 安装依赖 ```bash # 使用poetry安装 poetry install # 或者使用pip pip install requests python-dotenv jsonschema ``` ### 2. 配置环境变量 复制.env.example为.env,配置你的Anthropic API Key: ```env ANTHROPIC_API_KEY=your_api_key_here ``` ### 3. 运行示例 ```bash cd agent python examples/demo.py ``` ### 4. 基本使用 ```python from agent.core.agent import Agent from agent.tools.base import BaseTool, ToolParameter from agent.tools.registry import tool_registry # 自定义工具 class MyTool(BaseTool): name = "my_tool" description = "我的自定义工具" parameters = [ ToolParameter(name="param1", type="string", description="参数1", required=True) ] def execute(self, parameters): return {"result": f"Hello {parameters['param1']}"} # 注册工具 tool_registry.register(MyTool()) # 初始化Agent agent = Agent(reflection_strategy="react") # 对话 response = agent.chat("你好,使用my_tool,参数是World") print(response) ``` ## 反思策略说明 1. **CoT(思维链)**:引导LLM分步思考,拆解复杂问题,适合需要推理的场景 2. **ReAct**:实现"思考-行动-观察"循环,适合需要多步工具调用的任务 3. **Self-Reflection**:自我检查回答准确性,自动修正错误,提升回答质量 ## 自定义扩展 ### 自定义工具 继承`BaseTool`类,实现`execute`方法,注册到`tool_registry`即可。 ### 自定义技能 继承`BaseSkill`类,实现`execute`方法和`trigger_keywords`,注册到`skill_registry`即可。 ### 自定义反思策略 继承`BaseReflection`类,实现`before_llm_call`、`after_llm_call`、`after_tool_call`方法即可。 ## 许可证 MIT