Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Cleanup
Tomas Valenta07d6f6bd8e6e
diff --git a/api-service/codegen/callbacks/logs.py b/api-service/codegen/callbacks/logs.pyindex 932a92db1..7168dad5c 100644--- a/api-service/codegen/callbacks/logs.py+++ b/api-service/codegen/callbacks/logs.py@@ -15,10 +15,38 @@ class LogStreamParser:self._token_buffer: str = ""# These logs can be partially parsed or they can have missing outputs.+ # They are flushed to self._logs after outputs for all tools in self._logs.buffer are ingested.self._logs_buffer: List[Dict[str, str]] = []# This is a list of tools' outputs that corresponds to the tool logs in the self._logs.buffer.self._tools_output_buffer: List[Dict[str, str]] = []+ def _parse(self):+ """This function should be called only after ingesting new token or tool output to update the buffered logs."""+ thought, action_string = separate_thought_and_action(self._token_buffer)+ action_logs = [+ {"type": "tool", "name": action.attrib["tool"], "input": action.text or ""}+ for action in parse_action_string(action_string)+ ]++ # Update action logs with the information from ingested tools' outputs.+ for i in range(len(self._tools_output_buffer)):+ action_logs[i] = {+ **action_logs[i],+ **self._tools_output_buffer[i],+ }++ # We overwrite the current buffered logs with their newer version.+ # If you ingested token or tool output this will save the change so you can call self.get_logs and get the new logs.+ self._logs_buffer = [+ {+ "type": "thought",+ "content": thought.removeprefix("Thought:")+ .replace("Action:", "")+ .strip(),+ },+ *action_logs,+ ]+def ingest_token(self, token: str):"""Ingest token and update the logs."""self._token_buffer += token@@ -26,7 +54,7 @@ class LogStreamParser:return selfdef ingest_tool_output(self, output: str):- """Ingest output from tool and update logs."""+ """Ingest output from tool and update the logs."""self._tools_output_buffer.append({"finish_at": str(datetime.datetime.now()),@@ -53,33 +81,6 @@ class LogStreamParser:*self._logs_buffer,]- def _parse(self):- """This function should be called only after ingesting new token or tool output to update the buffered logs."""- thought, action_string = separate_thought_and_action(self._token_buffer)- action_logs = [- {"type": "tool", "name": action.attrib["tool"], "input": action.text or ""}- for action in parse_action_string(action_string)- ]-- # Update action logs with the information from ingested tools' outputs.- for i in range(len(self._tools_output_buffer)):- action_logs[i] = {- **action_logs[i],- **self._tools_output_buffer[i],- }-- # We overwrite the current buffered logs with their newer version.- # If you ingested token or tool output this will save the change so you can call self.get_logs and get the new logs.- self._logs_buffer = [- {- "type": "thought",- "content": thought.removeprefix("Thought:")- .replace("Action:", "")- .strip(),- },- *action_logs,- ]-class LogsCallbackHandler(BaseCallbackHandler):_database: Database = PrivateAttr()