agentic system stream changes

This commit is contained in:
Ashwin Bharambe 2024-07-09 15:08:54 -07:00
parent 97f9b18aca
commit 256f1d5991
4 changed files with 282 additions and 18 deletions

View file

@ -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]

View file

@ -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

View file

@ -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": "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",

View file

@ -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:
- turn
- 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:
- 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:
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: <SchemaDefinition schemaRef="#/components/schemas/AgenticSystemCreateRequest"
/>
name: AgenticSystemCreateRequest