Download src/dynamic_tool_agent/executor.py from hibanail/langgraph-demo: direct link, hf CLI and curl.
- Browser
- Download file 934 Bytes
-
https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/executor.py
- Command line
-
hf download hf://hibanail/langgraph-demo/src/dynamic_tool_agent/executor.py
-
curl -L -o executor.py https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/executor.py
934 Bytes
| 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 | |
| } | |