MCPcopy Index your code
hub / github.com/LangGraph-GUI/LangGraph-GUI-backend / execute_tool

Function execute_tool

src/WorkFlow.py:69–102  ·  view source on GitHub ↗
(name: str, state: PipelineState, prompt_template: str, llm)

Source from the content-addressed store, hash-verified

67 return state
68
69def execute_tool(name: str, state: PipelineState, prompt_template: str, llm) -> PipelineState:
70
71 logger(f"{name} is working...")
72
73 state["history"] = clip_history(state["history"])
74
75 generation = create_llm_chain(prompt_template, llm, state["history"])
76
77 # Sanitize the generation output by removing invalid control characters
78 sanitized_generation = re.sub(r'[\x00-\x1F\x7F]', '', generation)
79
80 logger(sanitized_generation)
81
82 data = json.loads(sanitized_generation)
83
84 choice = data
85 tool_name = choice["function"]
86 args = choice["args"]
87
88 if tool_name not in tool_registry:
89 raise ValueError(f"Tool {tool_name} not found in registry.")
90
91 result = tool_registry[tool_name](*args)
92
93 # Flatten args to a string
94 flattened_args = ', '.join(map(str, args))
95
96 logger(f"\nExecuted Tool: {tool_name}({flattened_args}) Result is: {result}")
97
98
99 state["history"] += f"\nExecuted {tool_name}({flattened_args}) Result is: {result}"
100 state["history"] = clip_history(state["history"])
101
102 return state
103
104def condition_switch(name:str, state: PipelineState, prompt_template: str, llm) -> PipelineState:
105 logger(f"{name} is working...")

Callers 1

build_subgraphFunction · 0.85

Calls 3

loggerFunction · 0.90
clip_historyFunction · 0.90
create_llm_chainFunction · 0.90

Tested by

no test coverage detected