Skip to main content

agent-base

agent-base 是一个用于快速搭建智能体项目脚手架的 Python 库,核心目标是:

  • 通过 CLI 一键创建智能体工程目录
  • 自动生成 .envagent.py、技能目录、本地函数目录、MCP 工具集目录
  • 基于 google-adk 统一加载模型、Skills、本地函数工具、远端 MCP 工具

项目结构

核心代码位于 src/agent_base

  • main.py:CLI 入口,解析命令并分发到 Operator
  • operator.py:脚手架生成与文件落地逻辑
  • agent_config.py:配置数据模型(Pydantic)
  • adk_agent.py:智能体运行时封装,负责动态加载工具与技能
  • observability/tracing.py:OpenTelemetry Trace 初始化
  • templates/*.template:新建智能体时使用的代码和环境变量模板

依赖与版本

pyproject.toml 中定义:

  • Python: >=3.10
  • 核心依赖:
    • google-adk[extensions]>=1.27.0
    • pydantic_yaml>=1.6.0
  • 命令行入口:
    • agent-base = agent_base.main:main

CLI 功能说明

1) 创建智能体

agent-base -an <agent_name> create-agent \
  -ad "<description>" \
  -ai "<instruction>" \
  -mdu "<model_base_url>" \
  -mdn "<model_name>" \
  -mdk "<model_api_key>" \
  -mdt 0.0 \
  -teh "<trace_endpoint_host>"

执行后会在当前目录下生成:

./<agent_name>/
  ├── .env
  ├── __init__.py
  ├── agent.py
  ├── skills/
  ├── local-functions/
  │   └── function_toolset.py
  └── mcp-toolsets/

2) 创建 MCP 工具集配置

agent-base -an <agent_name> create-mcp-toolset \
  -mpn "<mcp_name>" \
  -mpu "<mcp_url>" \
  -mpst "SSE|StreamableHTTP" \
  -mpat "<optional_token>"

会在 ./<agent_name>/mcp-toolsets/ 下生成对应 JSON 配置文件。

3) 预留命令(尚未实现)

  • create-skill
  • create-local-function-tool

当前在 operator.py 中仍是占位实现(pass 或空函数体)。


运行时加载机制(ADKAgent)

ADKAgent 初始化时会把三类能力合并到 tools

  1. 本地函数工具
    扫描 ./<agent_name>/local-functions/*.py,通过动态 import 抽取顶层函数并注册。

  2. Skills
    扫描 ./<agent_name>/skills/*,使用 google.adk.skills.load_skill_from_dir 加载后封装为 SkillToolset

  3. 远端 MCP 工具
    扫描 ./<agent_name>/mcp-toolsets/*.json,按 server_type 构建:

    • SSE -> SseServerParams
    • StreamableHTTP -> StreamableHTTPServerParams

Trace 能力

当提供 TRACE_ENDPOINT_HOST 时,会调用 setup_tracing(endpoint_host, experiment_id)

  • 使用 OTLP HTTP exporter 上报到 ${endpoint_host}/v1/traces
  • 额外写入 header:x-mlflow-experiment-id

experiment_id 在示例中由当前时间戳(毫秒)生成。


示例代码分析(tests/test_agent)

你本地示例目录中的 tests/test_agent/agent.py 展示了最小可运行初始化流程:

  1. 读取 .envdotenv
  2. 初始化 tracing(可选)
  3. 组装 AgentConfig + ModelProvider
  4. 构造 root_agent = ADKAgent(...)

示例技能中包含:

  • skills/calculator:通过 scripts/calculate.py 提供加减乘除脚本工具
  • skills/comment-news:给出“先搜新闻,再客观评价”的技能流程
  • skills/tavily-search:封装 Tavily CLI 的检索能力(含安装与命令范式)

当前实现特点与注意事项

已具备

  • 模板化创建智能体工程
  • 统一配置模型参数与工具加载
  • 可加载本地函数 + Skills + MCP toolsets

需要注意

  • operator.py 使用 os.system 进行目录与文件创建,后续可考虑改为 pathlib/shutil 提高可维护性与安全性。
  • create-skillcreate-local-function-tool 还未完成。
  • 示例 .env 中出现了真实样式的 API Key,建议立即替换并避免提交到版本库(应使用环境注入或密钥管理)。

快速开始(建议流程)

  1. 安装依赖并安装本包(开发模式)
  2. 通过 agent-base ... create-agent 生成智能体目录
  3. skills/local-functions/ 中补充能力
  4. 根据需要添加 mcp-toolsets/*.json
  5. 在生成的 agent.py 中实例化并运行智能体

如需扩展,建议优先补齐 create-skillcreate-local-function-tool 的自动化生成能力,这样项目可以形成完整的“从 0 到可运行”脚手架闭环。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_os_base-0.2.9.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_os_base-0.2.9-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file agent_os_base-0.2.9.tar.gz.

File metadata

  • Download URL: agent_os_base-0.2.9.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for agent_os_base-0.2.9.tar.gz
Algorithm Hash digest
SHA256 2fcd192702a16a63591a7d87de91c6677739b54ae044aa2bae7c39139f3b6017
MD5 80ff532f4c824fe472431803d9e791dc
BLAKE2b-256 a21894cc084d96fdc6a9f04fc8902c4570e7e000ebd5fd357b29813656f01af7

See more details on using hashes here.

File details

Details for the file agent_os_base-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: agent_os_base-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for agent_os_base-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4b767f198b99fda5957af372c0ff305ac7b37ff117b3a19392e74b4ab52a14b6
MD5 9a62227be97744ea7b3314bce2b08071
BLAKE2b-256 1b0cbbe413c04b88d4f2361ee04685b15418e75eb31667d6404f0f43036c30c7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.9 This release

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page