feat(agent-core): 增加智能编排与模型工具基础
This commit is contained in:
40
agent_core/tool_registry.py
Normal file
40
agent_core/tool_registry.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from .tools.builtin_tools import BUILTIN_TOOLS
|
||||
|
||||
|
||||
def run_declared_tools(tool_names: list[str], user_input: str) -> list[dict]:
|
||||
results = []
|
||||
for tool_name in tool_names:
|
||||
tool = BUILTIN_TOOLS.get(tool_name)
|
||||
if tool is None:
|
||||
results.append(
|
||||
{
|
||||
"tool_name": tool_name,
|
||||
"success": False,
|
||||
"arguments": {"user_input": user_input},
|
||||
"result": {},
|
||||
"error": "工具未注册",
|
||||
}
|
||||
)
|
||||
continue
|
||||
try:
|
||||
result = tool(user_input=user_input)
|
||||
results.append(
|
||||
{
|
||||
"tool_name": tool_name,
|
||||
"success": True,
|
||||
"arguments": {"user_input": user_input},
|
||||
"result": result,
|
||||
"error": "",
|
||||
}
|
||||
)
|
||||
except Exception as exc:
|
||||
results.append(
|
||||
{
|
||||
"tool_name": tool_name,
|
||||
"success": False,
|
||||
"arguments": {"user_input": user_input},
|
||||
"result": {},
|
||||
"error": str(exc),
|
||||
}
|
||||
)
|
||||
return results
|
||||
Reference in New Issue
Block a user