diff --git a/trustgraph-base/trustgraph/api/async_socket_client.py b/trustgraph-base/trustgraph/api/async_socket_client.py index b68a69d5..7c2a5aab 100644 --- a/trustgraph-base/trustgraph/api/async_socket_client.py +++ b/trustgraph-base/trustgraph/api/async_socket_client.py @@ -130,18 +130,26 @@ class AsyncSocketClient: content=resp.get("content", ""), end_of_message=resp.get("end_of_message", False) ) - elif chunk_type == "final-answer": + elif chunk_type == "answer" or chunk_type == "final-answer": return AgentAnswer( content=resp.get("content", ""), end_of_message=resp.get("end_of_message", False), end_of_dialog=resp.get("end_of_dialog", False) ) + elif chunk_type == "action": + # Agent action chunks - treat as thoughts for display purposes + return AgentThought( + content=resp.get("content", ""), + end_of_message=resp.get("end_of_message", False) + ) else: # RAG-style chunk (or generic chunk) + # Text-completion uses "response" field, RAG uses "chunk" field, Prompt uses "text" field + content = resp.get("response", resp.get("chunk", resp.get("text", ""))) return RAGChunk( - content=resp.get("chunk", ""), + content=content, end_of_stream=resp.get("end_of_stream", False), - error=resp.get("error") + error=None # Errors are always thrown, never stored ) async def aclose(self): diff --git a/trustgraph-base/trustgraph/api/socket_client.py b/trustgraph-base/trustgraph/api/socket_client.py index 09e937e6..c0fd9cd9 100644 --- a/trustgraph-base/trustgraph/api/socket_client.py +++ b/trustgraph-base/trustgraph/api/socket_client.py @@ -202,12 +202,18 @@ class SocketClient: content=resp.get("content", ""), end_of_message=resp.get("end_of_message", False) ) - elif chunk_type == "final-answer": + elif chunk_type == "answer" or chunk_type == "final-answer": return AgentAnswer( content=resp.get("content", ""), end_of_message=resp.get("end_of_message", False), end_of_dialog=resp.get("end_of_dialog", False) ) + elif chunk_type == "action": + # Agent action chunks - treat as thoughts for display purposes + return AgentThought( + content=resp.get("content", ""), + end_of_message=resp.get("end_of_message", False) + ) else: # RAG-style chunk (or generic chunk) # Text-completion uses "response" field, RAG uses "chunk" field, Prompt uses "text" field diff --git a/trustgraph-base/trustgraph/api/types.py b/trustgraph-base/trustgraph/api/types.py index 016f2c7a..bba566a6 100644 --- a/trustgraph-base/trustgraph/api/types.py +++ b/trustgraph-base/trustgraph/api/types.py @@ -79,5 +79,6 @@ class AgentAnswer(StreamingChunk): @dataclasses.dataclass class RAGChunk(StreamingChunk): """RAG streaming chunk""" + chunk_type: str = "rag" end_of_stream: bool = False error: Optional[Dict[str, str]] = None