Download src/dynamic_tool_agent/state.py from hibanail/langgraph-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/state.py
- Command line
-
hf download hf://hibanail/langgraph-demo/src/dynamic_tool_agent/state.py
-
curl -L -o state.py https://huggingface.co/hibanail/langgraph-demo/resolve/main/src/dynamic_tool_agent/state.py
1.57 kB
| from typing import TypedDict, Annotated, Any | |
| from langchain_core.messages import AnyMessage | |
| from langgraph.graph.message import add_messages | |
| tools_config = [ | |
| { | |
| "name": "book_table", | |
| "description": "Book a table at a restaurant", | |
| "parameters": [ | |
| {"name": "restaurant", "type": "string", "required": True}, | |
| {"name": "people", "type": "integer", "required": True}, | |
| {"name": "date", "type": "string", "required": True}, | |
| {"name": "time", "type": "string", "required": True} | |
| ] | |
| }, | |
| { | |
| "name": "check_menu", | |
| "description": "Check if a dish is on the restaurant menu", | |
| "parameters": [ | |
| {"name": "restaurant", "type": "string", "required": True}, | |
| {"name": "dish", "type": "string", "required": True} | |
| ] | |
| } | |
| ] | |
| def build_parameter_catalog(tools_config): | |
| catalog = {} | |
| for tool in tools_config: | |
| for param in tool["parameters"]: | |
| name = param["name"] | |
| if name not in catalog: | |
| catalog[name] = { | |
| "type": param["type"] | |
| } | |
| return catalog | |
| parameter_catalog = build_parameter_catalog(tools_config) | |
| def merge_dicts(old: dict, new: dict) -> dict: | |
| return {**old, **new} | |
| class AgentState(TypedDict): | |
| messages: Annotated[list[AnyMessage], add_messages] | |
| global_params: Annotated[dict[str, Any], merge_dicts] | |
| selected_tool: str | None | |
| missing_params: list[str] | |
| tool_args: dict[str, Any] | |
| tool_result: dict[str, Any] | None |