from .state import AgentState, tools_config from .tools import TOOL_REGISTRY def execute_tool(state: AgentState): tool_name = state["selected_tool"] args = state["tool_args"] # Make sure the tool exists if tool_name not in TOOL_REGISTRY: return { "tool_result": { "status": "error", "message": "Unknown tool" } } tool_config = next( t for t in tools_config if t["name"] == tool_name ) allowed = { p["name"] for p in tool_config["parameters"] } if not set(args).issubset(allowed): return { "tool_result": { "status": "error", "message": "Unexpected tool arguments" } } # Execute the selected function function = TOOL_REGISTRY[tool_name] result = function(**args) return { "tool_result": result }