From 256f1d5991568483659343cf5ae6f7ce386ba1fa Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Tue, 9 Jul 2024 15:08:54 -0700 Subject: [PATCH] agentic system stream changes --- source/agentic_system_types.py | 9 +- source/api_definitions.py | 29 ++++-- source/openapi.html | 157 +++++++++++++++++++++++++++++++-- source/openapi.yaml | 105 ++++++++++++++++++++-- 4 files changed, 282 insertions(+), 18 deletions(-) diff --git a/source/agentic_system_types.py b/source/agentic_system_types.py index f5548a9be..9e2e8b1a8 100644 --- a/source/agentic_system_types.py +++ b/source/agentic_system_types.py @@ -32,6 +32,7 @@ class ExecutionStepBase: """An agentic system turn can consist of one or more such execution steps.""" step_type: ExecutionStepType + uuid: str @dataclass @@ -63,10 +64,16 @@ class SafetyFilteringStep(ExecutionStepBase): violation: Optional[SafetyViolation] = None +@dataclass +class IndexedMemoryDocument: + index_id: str + content: str + + @dataclass class MemoryRetrievalStep(ExecutionStepBase): step_type = ExecutionStepType.memory_retrieval - documents: List[str] + documents: List[IndexedMemoryDocument] scores: List[float] diff --git a/source/api_definitions.py b/source/api_definitions.py index 71d8dbf4a..882adc4e9 100644 --- a/source/api_definitions.py +++ b/source/api_definitions.py @@ -3,6 +3,12 @@ from enum import Enum from typing import Any, Dict, List, Optional, Protocol, Set, Union import yaml +from agentic_system_types import ( + AgenticSystemTurn, + ExecutionStepType, + IndexedMemoryDocument, + SafetyViolation, +) from model_types import ( BuiltinTool, @@ -16,9 +22,6 @@ from model_types import ( ToolDefinition, ToolResponse, ) -from agentic_system_types import ( - AgenticSystemTurn, -) from pyopenapi import Info, Options, Server, Specification, webmethod from strong_typing.schema import json_schema_type @@ -146,13 +149,29 @@ class AgenticSystemExecuteResponse: turn: AgenticSystemTurn +class AgenticSystemExecuteResponseEventType(Enum): + """The type of event.""" + + step_start = "step_start" + step_end = "step_end" + step_progress = "step_progress" + + @json_schema_type @dataclass class AgenticSystemExecuteResponseStreamChunk: """Streamed agent execution response.""" - # TODO: make things streamable - turn: AgenticSystemTurn + event_type: AgenticSystemExecuteResponseEventType + + step_uuid: str + step_type: ExecutionStepType + + violation: Optional[SafetyViolation] = None + tool_call: Optional[ToolCall] = None + tool_response_delta: Optional[ToolResponse] = None + response_text_delta: Optional[str] = None + retrieved_document: Optional[IndexedMemoryDocument] = None stop_reason: Optional[StopReason] = None diff --git a/source/openapi.html b/source/openapi.html index 3826377cf..098441efa 100644 --- a/source/openapi.html +++ b/source/openapi.html @@ -328,6 +328,9 @@ "title": "The type of execution step.", "default": "model_inference" }, + "uuid": { + "type": "string" + }, "text": { "type": "string" }, @@ -360,6 +363,7 @@ "additionalProperties": false, "required": [ "step_type", + "uuid", "text" ] }, @@ -377,6 +381,9 @@ "title": "The type of execution step.", "default": "tool_execution" }, + "uuid": { + "type": "string" + }, "tool_calls": { "type": "array", "items": { @@ -442,6 +449,7 @@ "additionalProperties": false, "required": [ "step_type", + "uuid", "tool_calls", "tool_responses" ] @@ -460,6 +468,9 @@ "title": "The type of execution step.", "default": "safety_filtering" }, + "uuid": { + "type": "string" + }, "violation": { "type": "object", "properties": { @@ -482,7 +493,8 @@ }, "additionalProperties": false, "required": [ - "step_type" + "step_type", + "uuid" ] }, { @@ -499,10 +511,26 @@ "title": "The type of execution step.", "default": "memory_retrieval" }, + "uuid": { + "type": "string" + }, "documents": { "type": "array", "items": { - "type": "string" + "type": "object", + "properties": { + "index_id": { + "type": "string" + }, + "content": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "index_id", + "content" + ] } }, "scores": { @@ -515,6 +543,7 @@ "additionalProperties": false, "required": [ "step_type", + "uuid", "documents", "scores" ] @@ -677,8 +706,120 @@ "AgenticSystemExecuteResponseStreamChunk": { "type": "object", "properties": { - "turn": { - "$ref": "#/components/schemas/AgenticSystemTurn" + "event_type": { + "type": "string", + "enum": [ + "step_start", + "step_end", + "step_progress" + ], + "title": "The type of event." + }, + "step_uuid": { + "type": "string" + }, + "step_type": { + "type": "string", + "enum": [ + "model_inference", + "tool_execution", + "safety_filtering", + "memory_retrieval" + ], + "title": "The type of execution step." + }, + "violation": { + "type": "object", + "properties": { + "violation_type": { + "type": "string" + }, + "details": { + "type": "string" + }, + "suggested_user_response": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "violation_type", + "details" + ] + }, + "tool_call": { + "type": "object", + "properties": { + "tool_name": { + "type": "string" + }, + "arguments": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "array" + }, + { + "type": "object" + } + ] + } + } + }, + "additionalProperties": false, + "required": [ + "tool_name", + "arguments" + ], + "title": "A tool call is a request to a tool." + }, + "tool_response_delta": { + "type": "object", + "properties": { + "tool_name": { + "type": "string" + }, + "response": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "tool_name", + "response" + ] + }, + "response_text_delta": { + "type": "string" + }, + "retrieved_document": { + "type": "object", + "properties": { + "index_id": { + "type": "string" + }, + "content": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "index_id", + "content" + ] }, "stop_reason": { "type": "string", @@ -692,7 +833,9 @@ }, "additionalProperties": false, "required": [ - "turn" + "event_type", + "step_uuid", + "step_type" ], "title": "Streamed agent execution response." }, @@ -1202,10 +1345,10 @@ ], "tags": [ { - "name": "Inference" + "name": "AgenticSystem" }, { - "name": "AgenticSystem" + "name": "Inference" }, { "name": "AgenticSystemCreateRequest", diff --git a/source/openapi.yaml b/source/openapi.yaml index 45cb2c8c2..caa2d5b02 100644 --- a/source/openapi.yaml +++ b/source/openapi.yaml @@ -94,6 +94,36 @@ components: AgenticSystemExecuteResponseStreamChunk: additionalProperties: false properties: + event_type: + enum: + - step_start + - step_end + - step_progress + title: The type of event. + type: string + response_text_delta: + type: string + retrieved_document: + additionalProperties: false + properties: + content: + type: string + index_id: + type: string + required: + - index_id + - content + type: object + step_type: + enum: + - model_inference + - tool_execution + - safety_filtering + - memory_retrieval + title: The type of execution step. + type: string + step_uuid: + type: string stop_reason: enum: - not_stopped @@ -102,10 +132,54 @@ components: title: Stop reasons are used to indicate why the model stopped generating text. type: string - turn: - $ref: '#/components/schemas/AgenticSystemTurn' + tool_call: + additionalProperties: false + properties: + arguments: + additionalProperties: + oneOf: + - type: 'null' + - type: boolean + - type: number + - type: string + - type: array + - type: object + type: object + tool_name: + type: string + required: + - tool_name + - arguments + title: A tool call is a request to a tool. + type: object + tool_response_delta: + additionalProperties: false + properties: + response: + type: string + tool_name: + type: string + required: + - tool_name + - response + type: object + violation: + additionalProperties: false + properties: + details: + type: string + suggested_user_response: + type: string + violation_type: + type: string + required: + - violation_type + - details + type: object required: - - turn + - event_type + - step_uuid + - step_type title: Streamed agent execution response. type: object AgenticSystemTurn: @@ -139,8 +213,11 @@ components: type: string text: type: string + uuid: + type: string required: - step_type + - uuid - text type: object - additionalProperties: false @@ -189,8 +266,11 @@ components: - response type: object type: array + uuid: + type: string required: - step_type + - uuid - tool_calls - tool_responses type: object @@ -205,6 +285,8 @@ components: - memory_retrieval title: The type of execution step. type: string + uuid: + type: string violation: additionalProperties: false properties: @@ -220,12 +302,22 @@ components: type: object required: - step_type + - uuid type: object - additionalProperties: false properties: documents: items: - type: string + additionalProperties: false + properties: + content: + type: string + index_id: + type: string + required: + - index_id + - content + type: object type: array scores: items: @@ -240,8 +332,11 @@ components: - memory_retrieval title: The type of execution step. type: string + uuid: + type: string required: - step_type + - uuid - documents - scores type: object @@ -720,8 +815,8 @@ security: servers: - url: http://llama.meta.com tags: -- name: Inference - name: AgenticSystem +- name: Inference - description: name: AgenticSystemCreateRequest