通用代理工具
从Universal Agent Nexus示例中提取的可重用工具和实用程序。
概述
此包包含生产就绪、可重复使用的组件,用于:
- Ollama+工具集成 -Ollama LLM与MCP工具的工作模式
- 代码分块 -多格式智能分块(Python、YAML、Markdown、JSON)
- MCP服务器框架 -创建MCP兼容服务器的基类
- 工具注册表 -集中工具发现和管理
- 代码库分析器 -AST解析、依赖图、PageRank评分
- GitHub集成 -基于CLI的GitHub操作
- 文档生成器 -结构化文档生成
- 同步状态管理 -通用同步状态跟踪
安装
pip install universal-agent-tools或者使用可选依赖项进行安装:
# With Qdrant support
pip install universal-agent-tools[qdrant]
# With GitHub API support
pip install universal-agent-tools[github]
# Development dependencies
pip install universal-agent-tools[dev]快速开始
Ollama+工具
from universal_agent_tools.ollama_tools import (
MCPToolLoader,
create_llm_with_tools
)
# Load tools from MCP server
tools = MCPToolLoader.load_from_server("http://localhost:8000/mcp")
# Create LLM with tools
llm, tools = create_llm_with_tools(tools, model="qwen2.5-coder:14b")代码分块
from universal_agent_tools.code_chunking import chunk_content
# Chunk any file type
chunks = chunk_content(content, "example.py")
# Each chunk has: type, name, content, line_start, line_end, docstring
for chunk in chunks:
print(f"{chunk['type']}: {chunk['name']} (lines {chunk['line_start']}-{chunk['line_end']})")工具注册表
from universal_agent_tools.tool_registry import get_registry
registry = get_registry()
registry.register_server("filesystem", "http://localhost:8000/mcp")
tools = registry.discover_tools()
for tool in registry.list_tools():
print(f"{tool.name}: {tool.description}")建筑
此套餐如下 SOLID设计原则:
- 单一责任 -每个模块都有一个明确的目的
- 打开/关闭 -无需修改即可扩展(例如,自定义分块器)
- 利斯科夫替补 -协议/接口确保可替代性
- 接口隔离 -专注、简洁的界面
- 依赖倒置 -依赖抽象,而非具体
组件
优先级1(生产就绪)
- ollama_tools/ -奥利玛+朗链+MCP集成
- 代码压缩/ -多格式分块系统
- mcp框架/ -MCP服务器框架
优先级2(测试良好)
- 工具注册/ -工具发现系统
- 代码库分析器/ -AST分析和依赖关系图
- github工具/ -GitHub CLI集成
优先级3(有用模式)
- 文档生成器/ -结构化文档生成
- 同步状态/ -通用同步状态跟踪
测试
# Run all tests
pytest
# With coverage
pytest --cov=universal_agent_tools
# Specific component
pytest tests/test_chunking.py许可证
MIT许可证
贡献
此包是从中提取的 universal_agent_nexus_examples. 看 REFACTORING_ANALYSIS.md 在示例仓库中获取提取细节。
