diff --git a/frontend/src/app/chat/page.tsx b/frontend/src/app/chat/page.tsx index 342fcf25..5b193e30 100644 --- a/frontend/src/app/chat/page.tsx +++ b/frontend/src/app/chat/page.tsx @@ -17,9 +17,22 @@ interface Message { interface FunctionCall { name: string arguments?: Record - result?: Record + result?: Record | ToolCallResult[] status: "pending" | "completed" | "error" argumentsString?: string + id?: string + type?: string +} + +interface ToolCallResult { + text_key?: string + data?: { + file_path?: string + text?: string + [key: string]: unknown + } + default_value?: string + [key: string]: unknown } type EndpointType = "chat" | "langflow" @@ -538,6 +551,56 @@ export default function ChatPage() { } } + // Handle tool call completion with results (new format) + else if (chunk.type === "response.output_item.done" && chunk.item?.type?.includes("_call")) { + console.log("Tool call done with results (new format):", chunk.item) + + // Find existing function call by ID, or by name/type if ID not available + let functionCall = currentFunctionCalls.find(fc => + fc.id === chunk.item.id || + (fc.name === chunk.item.type) || + (fc.name.includes(chunk.item.type.replace('_call', '')) || chunk.item.type.includes(fc.name)) + ) + + if (functionCall) { + // Update existing function call + functionCall.arguments = chunk.item.inputs || functionCall.arguments + functionCall.status = chunk.item.status === "completed" ? "completed" : "error" + functionCall.id = chunk.item.id + functionCall.type = chunk.item.type + + // Set the results + if (chunk.item.results) { + functionCall.result = chunk.item.results + } + } else { + // Only create new if we really can't find an existing one + console.log("Creating new function call for:", chunk.item.type) + functionCall = { + name: chunk.item.type || "unknown", + arguments: chunk.item.inputs || {}, + status: "completed" as const, + id: chunk.item.id, + type: chunk.item.type, + result: chunk.item.results + } + currentFunctionCalls.push(functionCall) + } + } + + // Handle function call output item added (new format) + else if (chunk.type === "response.output_item.added" && chunk.item?.type?.includes("_call")) { + console.log("Tool call started (new format):", chunk.item) + const functionCall = { + name: chunk.item.type || "unknown", + arguments: chunk.item.inputs || {}, + status: "pending" as const, + id: chunk.item.id, + type: chunk.item.type + } + currentFunctionCalls.push(functionCall) + } + // Handle function call results else if (chunk.type === "response.function_call.result" || chunk.type === "function_call_result") { console.log("Function call result:", chunk.result || chunk) @@ -768,9 +831,39 @@ export default function ChatPage() { {fc.result && (
Result: -
-                        {JSON.stringify(fc.result, null, 2)}
-                      
+ {Array.isArray(fc.result) ? ( +
+ {fc.result.map((result, idx) => ( +
+ {result.data?.file_path && ( +
+ 📄 {result.data.file_path || "Unknown file"} +
+ )} + {result.data?.text && ( +
+ {result.data.text.length > 300 + ? result.data.text.substring(0, 300) + "..." + : result.data.text + } +
+ )} + {result.text_key && ( +
+ Key: {result.text_key} +
+ )} +
+ ))} +
+ Found {fc.result.length} result{fc.result.length !== 1 ? 's' : ''} +
+
+ ) : ( +
+                          {JSON.stringify(fc.result, null, 2)}
+                        
+ )}
)} diff --git a/src/agent.py b/src/agent.py index 7f6d8736..93eeca1c 100644 --- a/src/agent.py +++ b/src/agent.py @@ -15,7 +15,8 @@ async def async_response_stream(client, prompt: str, model: str, previous_respon request_params = { "model": model, "input": prompt, - "stream": True + "stream": True, + "include": ["tool_call.results"] } if previous_response_id is not None: request_params["previous_response_id"] = previous_response_id @@ -76,7 +77,8 @@ async def async_response(client, prompt: str, model: str, previous_response_id: request_params = { "model": model, "input": prompt, - "stream": False + "stream": False, + "include": ["tool_call.results"] } if previous_response_id is not None: request_params["previous_response_id"] = previous_response_id