MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / run_live_tool_loop_for_node

Method run_live_tool_loop_for_node

python/src/workflow/executor.rs:1178–1540  ·  view source on GitHub ↗
(
        node_id: &str,
        node_name: &str,
        initial_output: &serde_json::Value,
        workflow: &graphbit_core::workflow::Workflow,
        llm_config: graphbit_core::llm::LlmConfig,
 

Source from the content-addressed store, hash-verified

1176 }
1177
1178 async fn run_live_tool_loop_for_node(
1179 node_id: &str,
1180 node_name: &str,
1181 initial_output: &serde_json::Value,
1182 workflow: &graphbit_core::workflow::Workflow,
1183 llm_config: graphbit_core::llm::LlmConfig,
1184 guardrail_enforcer: Option<Arc<Enforcer>>,
1185 event_tx: &tokio::sync::mpsc::Sender<TimedStreamEvent>,
1186 stream_mode: StreamMode,
1187 ) -> Result<
1188 (String, Vec<serde_json::Value>, Vec<String>, String),
1189 graphbit_core::errors::GraphBitError,
1190 > {
1191 use crate::workflow::node::execute_production_tool_calls;
1192 use graphbit_core::llm::{LlmMessage, LlmProvider, LlmTool, LlmToolCall};
1193
1194 let response_obj = initial_output;
1195 let initial_tool_calls = response_obj
1196 .get("tool_calls")
1197 .and_then(|v| v.as_array())
1198 .cloned()
1199 .unwrap_or_default();
1200 let original_prompt = response_obj
1201 .get("original_prompt")
1202 .and_then(|v| v.as_str())
1203 .unwrap_or("");
1204 let initial_content = response_obj
1205 .get("content")
1206 .and_then(|v| v.as_str())
1207 .unwrap_or("")
1208 .to_string();
1209
1210 let node = workflow
1211 .graph
1212 .get_nodes()
1213 .iter()
1214 .find(|(id, _)| id.to_string() == node_id)
1215 .map(|(_, node)| node.clone())
1216 .ok_or_else(|| {
1217 graphbit_core::errors::GraphBitError::workflow_execution(format!(
1218 "Node '{node_id}' not found while running live tool loop",
1219 ))
1220 })?;
1221
1222 let node_tools = Self::extract_node_tools(&node.config);
1223 let llm_tools: Vec<LlmTool> = Self::extract_llm_tools(&node.config);
1224 let max_iterations = Self::extract_max_iterations(&node.config, 10);
1225
1226 let llm_provider =
1227 graphbit_core::llm::LlmProviderFactory::create_provider(llm_config.clone())
1228 .map(|provider_trait| LlmProvider::new(provider_trait, llm_config.clone()))
1229 .map_err(|e| {
1230 graphbit_core::errors::GraphBitError::workflow_execution(format!(
1231 "Failed to create LLM provider for live streaming loop: {e}",
1232 ))
1233 })?;
1234
1235 let mut messages: Vec<LlmMessage> = vec![LlmMessage::user(original_prompt)];

Callers

nothing calls this directly

Calls 12

toolFunction · 0.85
error_type_from_stringFunction · 0.85
to_stringMethod · 0.80
get_nodesMethod · 0.80
cloneMethod · 0.80
decodeMethod · 0.80
insertMethod · 0.80
getMethod · 0.45
with_tool_callsMethod · 0.45
model_nameMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected