Download src/dynamic_tool_agent/validator.py from hibanail/langgraph-demo: direct link, hf CLI and curl.
- Browser
- Download file 838 Bytes
-
https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/validator.py
- Command line
-
hf download hf://hibanail/langgraph-demo/src/dynamic_tool_agent/validator.py
-
curl -L -o validator.py https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/validator.py
838 Bytes
| from .state import AgentState, tools_config | |
| def validate_tool(state: AgentState): | |
| selected_tool = state["selected_tool"] | |
| # Find selected tool configuration | |
| tool = next( | |
| (t for t in tools_config | |
| if t["name"] == selected_tool), | |
| None | |
| ) | |
| if tool is None: | |
| return { | |
| "tool_args": {}, | |
| "missing_params": [] | |
| } | |
| global_params = state["global_params"] | |
| tool_args = {} | |
| missing = [] | |
| for param in tool["parameters"]: | |
| name = param["name"] | |
| required = param["required"] | |
| value = global_params.get(name) | |
| if value is None: | |
| if required: | |
| missing.append(name) | |
| else: | |
| tool_args[name] = value | |
| return { | |
| "tool_args": tool_args, | |
| "missing_params": missing | |
| } | |