当前位置: 首页 > news >正文

Agent Builder API - Agent Smith 扩展的后端服务(开源代码)

​一、软件介绍

文末提供程序和源码下载

        Agent Builder API - Agent Smith 扩展的后端服务(开源代码)手动设置:在本地计算机中克隆此存储库并启动 python FAST API 服务器。(可选)安装并设置 Mongo DB。Dev Container 设置:Dev Containers 允许您自动执行环境设置。使用此设置可在预安装了扩展的隔离环境中安装和运行容器服务。您还可以使用密钥在远程环境/浏览器中打开 GitHub Codespaces 以传递模型 API 密钥。

二、Manual Setup 手动设置

  1. Set up a Python virtualenv and install dependencies
    设置 Python virtualenv 并安装依赖项

    python -m venv --prompt agent-builder-api venv
    source venv/Scripts/activate
    # venv/Scripts/activate (Windows PS)
    pip install -r requirements.txt
  2. Set the model name and API key in .env file
    在 .env 文件中设置模型名称和 API 密钥

    OPENAI_API_KEY="sk----"
    MODEL_NAME="openai"
  3. Start the server in the new terminal
    在新终端中启动服务器

    python -m agentbuilder.main
[Optional] Start using Poetry
[可选]开始使用 Poetry

For fine-grained dependency management, use Poetry to pick and choose dependency packs based on your LLM model provider and tool features.
对于精细的依赖项管理,请使用 Poetry 根据您的LLM模型提供程序和工具功能来挑选依赖项包。

  1. Follow the Offical Instruction Guide to install Poetry.
    按照 官方说明指南安装 Poetry。

  2. Pick and choose dependency packs to install.
    选择要安装的依赖项包。

    poetry install --extras "mcp openai gemini cohere anthropic mongodb vectordb langgraph guardrails ui"
  3. Set the model name and API key in .env file
    在 .env 文件中设置模型名称和 API 密钥

    OPENAI_API_KEY="sk----"
    MODEL_NAME="openai"
  4. Start the server in the new terminal
    在新终端中启动服务器

    poetry run start-server

Note 注意

Poetry will create a virtual environment for us.
诗歌将为我们创造一个虚拟环境。

MCP servers MCP 服务器
  • Local MCP servers can be added in MCP server folder
    可以在 MCP 服务器文件夹中添加本地 MCP 服务器

  • Multiple MCP clients can be configured in MPC client file
    可以在 MPC 客户端文件中配置多个 MCP 客户端

    mcp_servers={"math": {"command": sys.executable,"args": [f"{current_dir}\\servers\\math.py"],"transport": "stdio",}}
[Optional] Enable MongoDB
[可选]启用 MongoDB

By default, data is stored as JSON files. Enable storage in Mongo DB by setting url using the environment variable.
默认情况下,数据存储为 JSON 文件。通过使用环境变量设置 url 在 Mongo DB 中启用存储。

MONGODB_URL="mongodb://localhost:27017/llmdb"

三、Dev Containers Setup 开发容器设置

  1. Enable Dev Containers in vscode by following the steps in official documentation.
    按照官方文档中的步骤在 vscode 中启用 Dev Containers。

  2. Click on the badge below to run the services in an isolated container environment in a local machine.
    单击下面的徽章,在本地计算机的隔离容器环境中运行服务。

    This will clone the repo and start the API and Mongo DB container services.
    这将克隆存储库并启动 API 和 Mongo DB 容器服务。

Tip 提示

Use URL mongodb://mongodb:27017/llmdb in Mongo DB vscode extension to view storage data.
使用 Mongo DB vscode 扩展中的 URL mongodb://mongodb:27017/llmdb 查看存储数据。

  1. Execute F1 > Dev Containers: Attach to Running Container.. and select agent-builder-container.
    执行 F1 > Dev Containers:附加到正在运行的容器..,然后选择 agent-builder-container。

  2. Set the model name and API key in .env file
    在 .env 文件中设置模型名称和 API 密钥

    OPENAI_API_KEY="sk----"
    MODEL_NAME="openai"

四、Customization 定制

Dependency packs and environment configuration
依赖项包和环境配置

Dependency packs allow fine-grained package installations based on your requirements. Use the environment variable EXTRA_DEPS in the docker-compose file to update.
依赖项包允许根据您的要求进行精细的软件包安装。使用 docker-compose 文件中的环境变量 EXTRA_DEPS 进行更新。

install-extra-deps.sh script can be used in dev container mode if docker-compose is not available.
如果 docker-compose 不可用,则可以 install-extra-deps.sh Dev Container 模式下使用该脚本。

For example, the below environment configuration will install dependencies for the Gemini model, Mongo DB, Langchain Graph, and VectorDB
例如,以下环境配置将安装 Gemini 模型、Mongo DB、Langchain Graph 和 VectorDB 的依赖项

EXTRA_DEPS: "gemini,mongodb,langgraph,vectordb"

Tip 提示

Start with a basic dependency pack to support your model and add other features incrementally
从基本依赖项包开始以支持您的模型,并逐步添加其他功能

The following models are supported by its dependency pack
其依赖项包支持以下模型

Model 型Dependency pack 依赖项包ENV key name ENV 密钥名称
OPEN AI 开放人工智能openai OpenAI 公司OPENAI_API_KEY
GEMINI 双子座gemini 双子座GOOGLE_API_KEY
COHEREcohere 凝聚COHERE_API_KEY
ANTHROPIC ANTHROPIC 类anthropic 人为的ANTHROPIC_API_KEY

Some pre-configured tools require extra dependencies or API keys to get enabled.
某些预配置工具需要额外的依赖项或 API 密钥才能启用。

Tool 工具Dependency pack 依赖项包ENV key name ENV 密钥名称
internet_search-TAVILY_API_KEY
vectorstore_searchvectordb 矢量数据库EMBED_MODEL_NAME

Adding Tools 添加工具

Add custom Tools or Toolkits using tool factory module (agentbuilder/factory/tool_factory).
使用工具工厂模块 (agentbuilder/factory/tool_factory) 添加自定义工具或工具包。

  1. Create your tool 创建您的工具

    agentbuilder/tools/my_custom_tool.py
    代理构建器/工具/my_custom_tool.py

    from pathlib import Path
    from langchain_core.tools import tool
    from pydantic import BaseModel, Field@tool
    def my_custom_tool(a: int, b: int):
    """Custom Tool Description"""
    return a + bmy_custom_tool.name="custom_tool_name"
    my_custom_tool.description="Custom Tool Description"class field_inputs(BaseModel):
    a: int = Field(description="First input")
    b: int = Field(description="Second input")my_custom_tool.args_schema = sum_inputs
    my_custom_tool.metadata= {"file_path": str(Path(__file__).absolute())}
  2. Add your tool in get_all_tools method in tool_factory module.
    在 get_all_tools 模块tool_factory方法中添加您的工具。

    agentbuilder/factory/tool_factory.py
    代理生成器/工厂/tool_factory.py

    def get_all_tools()->Sequence[BaseTool]:return get_vectordb_tools()+ get_websearch_tools() + json_tools + [directly_answer_tool,weather_clothing_tool,temperature_tool,temperature_sensor_tool,sum_tool,greeting_tool,git_diff_tool,repl_tool,
    +           my_custom_tool]

Adding Agents 添加代理

Agents can be created using Extension UI or declared in code. Add your agents using the Agent Factory Module (agentbuilder/factory/agent_factory).
代理可以使用扩展 UI 创建,也可以在代码中声明。使用 Agent Factory 模块 (agentbuilder/factory/agent_factory) 添加代理。

  1. Create your agent 创建您的代理

    def my_agent():return AgentParams(name="my_agent",preamble= "You are a powerful agent that uses tools to answer Human questions",tools=  ["my_custom_tool"],agent_type= 'tool_calling')
  2. Add your agent in get_all_agents method.
    在 get_all_agents 方法中添加代理。

    def get_all_agents():
    return [default_agent(),weather_agent(),python_agent(),git_agent(),
    +       my_agent()
    ]

Custom Agent Builder and Graphs
自定义代理生成器和图表

Customize your Agent Workflow using custom prompts and graphs. Filter the agent using the agent name to apply customizations.
使用自定义提示和图表自定义您的代理工作流程。使用代理名称筛选代理以应用自定义。

For example, the following code applies graph builder workflow for the Agent named "graph_agent"
例如,以下代码将图形生成器工作流应用于名为“graph_agent”的代理

def get_agent_builder(params:AgentBuilderParams):agent_name= params.namematch agent_name:case "graph_agent":from agentbuilder.agents.BaseGraphAgentBuilder import BaseGraphAgentBuilderreturn BaseGraphAgentBuilder(params)case _:return BaseAgentBuilder(params)

Important 重要

Dependency pack "langgraph" needs to be installed for BaseGraphAgentBuilder.
需要为 BaseGraphAgentBuilder 安装依赖项包 “langgraph”。

Configuring models 配置模型

Update model configuration using environment variables.
使用环境变量更新模型配置。

Supports {Provider}/{ModelName} format
支持 {Provider}/{ModelName} 格式

  • Gemini 双子座

    Create API keys https://aistudio.google.com/app/apikey
    创建 API 密钥 https://aistudio.google.com/app/apikey

     MODEL_NAME="gemini/gemini-pro"EMBED_MODEL_NAME="gemini/embedding-001"GOOGLE_API_KEY=<GOOGLE_API_KEY>
  • Cohere 凝聚

    Create API keys Login | Cohere
    创建 API 密钥 https://dashboard.cohere.com/api-keys

     MODEL_NAME="cohere/command"EMBED_MODEL_NAME="cohere/embed-english-v3.0"COHERE_API_KEY=<COHERE_API_KEY>
  • Open AI 打开 AI

    Create API keys https://platform.openai.com/docs/quickstart/account-setup
    创建 API 密钥 https://platform.openai.com/docs/quickstart/account-setup

     MODEL_NAME="openai/gpt-4o"EMBED_MODEL_NAME="openai/text-embedding-3-large"OPENAI_API_KEY=<OPENAI_API_KEY>
  • Anthropic 人

    Create API keys Home \ Anthropic and Voyage AI | Home
    创建 API 密钥 https://www.anthropic.com/ 和 https://www.voyageai.com/

     MODEL_NAME="anthropic/claude-3-opus-20240229"EMBED_MODEL_NAME="voyageai/voyage-2"ANTHROPIC_API_KEY=<ANTHROPIC_API_KEY>VOYAGE_API_KEY=<VOYAGE_API_KEY>
  • Ollama 奥拉马

    Use local models for function calls.
    使用本地模型进行函数调用。

    [!TIP] Use JSON chat agent type for better compatibility with local models.
    [!提示] 使用 JSON 聊天代理类型以更好地与本地模型兼容。

    Install Ollama and pull the model.
    安装 Ollama 并拉取模型。

    ollama pull mistral:v0.3

    Set environment variable.
    设置环境变量。

    MODEL_NAME="ollama/mistral:v0.3"

五、软件下载

夸克网盘分享

本文信息来源于GitHub作者地址:https://github.com/nagaraj-real/agent-builder-api

相关文章:

  • 学习机器学习的体会与姓名性别预测案例分析
  • 智能工具协同赋能STEM教育科研|探索LLM大语言模型和数学软件Maple的创新实践
  • 反向操作:如何用AI检测工具优化自己的论文“人味”?
  • 华为云Flexus+DeepSeek征文|基于华为云ModelArts Studio平台体验DeepSeek-V3大模型
  • idea中编写spark程序
  • npm install 报错
  • CMD(Command Prompt)和 Anaconda 的不同
  • c# 倒序方法
  • 数据结构(八)——查找
  • 2025-5-14渗透测试:利用Printer Bug ,NTLMv2 Hash Relay(中继攻击),CVE-2019-1040漏洞复现
  • 环境配置与MySQL简介
  • css设置文字两端对齐text-align:justify不起作用的解决方法
  • C++之fmt库介绍和使用(1)
  • 【数据分析】从TCGA下载所有癌症的多组学数据
  • 【SSL证书系列】SSL证书工作原理解读
  • 开发者的测试复盘:架构分层测试策略与工具链闭环设计实战
  • 【电路笔记 通信】8B/10B编码 高速数据传输的串行数据编码技术 论文第三部分 The 8B/10B coding map
  • 论文查询的ai工具 —— SCAICH
  • ISP有感自发
  • 数据结构基础排序算法
  • 制造四十余年血腥冲突后,库尔德工人党为何自行解散?
  • 袁思达已任中国科学院办公厅主任
  • 中国-拉共体成员国重点领域合作共同行动计划(2025-2027)
  • 多家外资看好中国市场!野村建议“战术超配”,花旗上调恒指目标价
  • 乌方:泽连斯基只接受与普京会谈,拒见其他俄代表
  • 首映|奥斯卡最佳国际影片《我仍在此》即将公映