Skip to content

Commit f51a215

Browse files
committed
chore(builder): support tools in yaml file
1 parent 6573565 commit f51a215

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

docs/docs/agent.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ root_agent:
129129
backend: local
130130
knowledgebase:
131131
backend: opensearch
132+
tools:
133+
- module: demo_tool # tool 所在的模块
134+
func: greeting # tool 的函数名称
135+
- module: tools.tool
136+
func: count
137+
sub_agents:
132138
sub_agents:
133139
- ${sub_agent_1}
134140

@@ -147,8 +153,7 @@ from veadk.agent_builder import AgentBuilder
147153
agent = AgentBuilder().build(path="./agent.yaml")
148154
```
149155

150-
函数`build`接收3个参数
156+
函数`build`接收 2 个参数
151157

152158
- `path`:配置文件路径
153159
- `root_agent_identifier`:配置文件中主 Agent 的名称,默认为`root_agent`
154-
- `tools`:主 agent 挂载的工具列表(子 Agent 工具列表暂未推出)

veadk/agent_builder.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib
16+
1517
from google.adk.agents import BaseAgent
16-
from google.adk.agents.llm_agent import ToolUnion
1718
from omegaconf import OmegaConf
1819

1920
from veadk.a2a.remote_ve_agent import RemoteVeAgent
@@ -48,8 +49,20 @@ def _build(self, agent_config: dict) -> BaseAgent:
4849
sub_agents.append(agent)
4950
agent_config.pop("sub_agents")
5051

52+
tools = []
53+
if agent_config.get("tools", []):
54+
for tool in agent_config["tools"]:
55+
module_name = tool["module"]
56+
func_name = tool["func"]
57+
58+
module = importlib.import_module(module_name)
59+
func = getattr(module, func_name)
60+
61+
tools.append(func)
62+
agent_config.pop("tools")
63+
5164
agent_cls = AGENT_TYPES[agent_config["type"]]
52-
agent = agent_cls(**agent_config, sub_agents=sub_agents)
65+
agent = agent_cls(**agent_config, sub_agents=sub_agents, tools=tools)
5366

5467
logger.debug("Build agent done.")
5568

@@ -72,14 +85,10 @@ def build(
7285
self,
7386
path: str,
7487
root_agent_identifier: str = "root_agent",
75-
tools: list[ToolUnion] | None = None,
7688
) -> BaseAgent:
7789
config = self._read_config(path)
7890

7991
agent_config = config[root_agent_identifier]
8092
agent = self._build(agent_config)
8193

82-
if tools and isinstance(agent, Agent):
83-
agent.tools = tools
84-
8594
return agent

0 commit comments

Comments
 (0)