|
| 1 | +## LLMStudio Agents Documentation |
| 2 | + |
| 3 | +This is a brief overveiw of the main functions and data types you need to be aware of to interact with LLMStudio agents, to see examples of the usage of this wrapper with openai and bedrock agents see `weather_example_bedrock.py` and `weather_example_openai.py` in the examples folder |
| 4 | + |
| 5 | +### Functions |
| 6 | + |
| 7 | +#### `create_agent`: |
| 8 | + |
| 9 | + |
| 10 | +Function to create a new agent / assistant, takes a single `CreateAgentRequest` object as input that defines the fields of the newly created agent. |
| 11 | + |
| 12 | +Parameters: |
| 13 | +- request: `CreateAgentRequest` |
| 14 | + |
| 15 | +Returns: |
| 16 | +- `AgentBase` - agent object to be used when running requests |
| 17 | + |
| 18 | + |
| 19 | +#### `run_agent`: |
| 20 | + |
| 21 | +Creates a run request for the agent in question, this function is *non-blocking*, meaning it won't return a final result, simple a reference to a run to be later polled / retrieved. |
| 22 | + |
| 23 | +Parameters: |
| 24 | +- request: `RunAgentRequest` |
| 25 | + |
| 26 | +Returns: |
| 27 | +- `RunBase` - run object that can be used to retrieve the results |
| 28 | + |
| 29 | +#### `retrieve_result`: |
| 30 | + |
| 31 | +Retireves the result based on a provided reference to a previously started run, waits until the run is done in a synchronous way. This should |
| 32 | + |
| 33 | +Parameters: |
| 34 | +- request: `RunBase` |
| 35 | + |
| 36 | +Returns: |
| 37 | +- `ResultBase` - result of the run |
| 38 | + |
| 39 | +#### `submit_tool_outputs`: |
| 40 | + |
| 41 | +Parameters: |
| 42 | +- request: `RunBase` |
| 43 | + |
| 44 | +Returns: |
| 45 | +- `ResultBase` - result of the run |
| 46 | + |
| 47 | + |
| 48 | +### Data Types |
| 49 | + |
| 50 | +#### `CreateAgentRequest` |
| 51 | + |
| 52 | +`CreateAgentRequest` is a data type used to define the parameters required to create a new agent. |
| 53 | + |
| 54 | +Attributes: |
| 55 | +- `model` (str): The foundational model identifier for the agent. |
| 56 | +- `instructions` (Optional[str]): System prompt for the agent |
| 57 | +- `description` (Optional[str]): Agent description |
| 58 | +- `tools` (Optional[list[`Tool`]]): Tools the agent can use, specified in openai format |
| 59 | +- `name` (Optional[str]): Name for the agent. |
| 60 | +- `tool_resources` (Optional[`ToolResources`]): resources for code interpreter and vector search |
| 61 | +- `agent_resource_role_arn` (Optional[str]) **REQUIRED FOR BEDROCK**: ARN for resource access role. |
| 62 | +- `agent_alias` (Optional[str]) **REQUIRED FOR BEDROCK**: Alias for the agent |
| 63 | + |
| 64 | +#### `RunAgentRequest`: |
| 65 | + |
| 66 | +`RunAgentRequest` is a data type used to define the parameters required to run an existing agent. |
| 67 | + |
| 68 | +Attributes: |
| 69 | +- `agent_id` (str): The unique identifier of the agent to be run. |
| 70 | +- `alias_id` (Optional[str]) **REQUIRED FOR BEDROCK** : The alias identifier of the agent. |
| 71 | +- `thread_id` (Optional[str]): An optional identifier for the thread or conversation context. If one is not provided, a new thread will be create. |
| 72 | +- `messages` (Optional[List[`Message`]]): A list of messages representing the conversation history. Should only be used when using the RunAgentRequest as an input to the `run_agent` function |
| 73 | +- `tool_outputs` (Optional[List[`ToolOutput`]]): A list of outputs from tools that the agent can utilize. This should only be used when using the RunAgentRequest as an input to the `submit_tool_outputs` function |
| 74 | +- `run_id` (Optional[str]): An optional identifier to continue a previous run. his should only be used when using the RunAgentRequest as an input to the `submit_tool_outputs` function |
| 75 | + |
| 76 | +Functions: |
| 77 | + |
| 78 | +- `from_agent`: An auxiliary to create a `RunAgentRequest` instance from an `AgentBase` object. |
| 79 | + |
| 80 | + Parameters: |
| 81 | + - `agent` (`AgentBase`): The agent from which to create the request. |
| 82 | + - `thread_id` (Optional[str]): An optional identifier for the thread or conversation context. |
| 83 | + - `messages` (Optional[List[`Message`]]): A list of messages representing the conversation history. |
| 84 | + - `tool_outputs` (Optional[List[`ToolOutput`]]): A list of outputs from tools that the agent can utilize. |
| 85 | + - `run_id` (Optional[str]): An optional identifier to continue a previous run. |
| 86 | + |
| 87 | + Returns: |
| 88 | + - `RunAgentRequest`: A new instance of `RunAgentRequest` initialized with the provided parameters. |
| 89 | + |
| 90 | + |
| 91 | +#### `Tool` |
| 92 | + |
| 93 | +`Tool` is a data type used to specify tools that an agent can utilize. |
| 94 | + |
| 95 | +Attributes: |
| 96 | +- `type` (str): The type identifier of the tool. |
| 97 | +- `function` (Optional[`Function`]): The function definition associated with the tool, specified in OpenAI format. |
| 98 | + |
| 99 | + |
| 100 | +#### `Function` |
| 101 | + |
| 102 | +`Function` is a data type used to define a function associated with a tool, specified in OpenAI function format. |
| 103 | + |
| 104 | +Attributes: |
| 105 | +- `name` (str): The name of the function. |
| 106 | +- `description` (str): A brief description of the function's purpose. |
| 107 | +- `parameters` (`Parameters`): The parameters accepted by the function. |
| 108 | + |
| 109 | + |
| 110 | +#### `Parameters` |
| 111 | + |
| 112 | +`Parameters` is a data type used to define the parameters accepted by a function in OpenAI function format. |
| 113 | + |
| 114 | +Attributes: |
| 115 | +- `type` (str): The type of the parameters object (typically set to "object"). |
| 116 | +- `properties` (Dict): A dictionary specifying the properties (parameters) that the function accepts. |
| 117 | +- `required` (List[str]): A list of parameter names that are required. |
| 118 | + |
| 119 | + |
| 120 | +#### `ToolResources` |
| 121 | + |
| 122 | +`ToolResources` is a data type that contains resources required by certain tools used by the agent. |
| 123 | + |
| 124 | +Attributes: |
| 125 | +- `file_ids` (Optional[List[str]]): A list of file identifiers for use with the `code_interpreter` tool. |
| 126 | +- `vector_store_ids` (Optional[List[str]]): A list of vector store identifiers for use with the `file_search` tool. |
| 127 | + |
| 128 | + |
| 129 | +#### `ToolOutput` |
| 130 | + |
| 131 | +`ToolOutput` is a data type that represents the output from a tool after its execution by the agent. |
| 132 | + |
| 133 | +Attributes: |
| 134 | +- `tool_call_id` (Optional[str]): The unique identifier of the tool call instance. |
| 135 | +- `output` (Optional[str]): The result or output produced by the tool. |
| 136 | +- `action_group` (Optional[str]): The action group or category associated with the tool call. |
| 137 | +- `function_name` (Optional[str]): The name of the function associated with the executed tool. |
| 138 | + |
| 139 | +Functions: |
| 140 | +- `from_tool_call`: Class method that creates a `ToolOutput` instance from a given `ToolCall` and its output. |
| 141 | + |
| 142 | + Parameters: |
| 143 | + |
| 144 | + - `tool_call` (`ToolCall`): The `ToolCall` instance representing the tool call. |
| 145 | + - `tool_output` (`str`): The output produced by the tool. |
| 146 | + |
| 147 | + Returns: |
| 148 | + |
| 149 | + - `ToolOutput`: An instance of `ToolOutput` populated with data from the `ToolCall` and `tool_output`. |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +#### `RunBase` |
| 154 | + |
| 155 | +`RunBase` represents the essential information required to initiate or continue an agent's run within a conversation thread. |
| 156 | + |
| 157 | +Attributes: |
| 158 | +- `thread_id` (str): The unique identifier of the conversation thread. |
| 159 | +- `agent_id` (Optional[str]): The unique identifier of the agent handling the thread. Defaults to `None`. |
| 160 | + |
| 161 | +#### `ResultBase` |
| 162 | + |
| 163 | +`ResultBase` is a data type that encapsulates the result produced by the agent after processing a request. |
| 164 | + |
| 165 | +Attributes: |
| 166 | +- `thread_id` (str): The unique identifier of the conversation thread. |
| 167 | +- `messages` (List[`Message`]): A list of `Message` instances representing the conversation history, including both user and agent messages. |
| 168 | +- `run_id` (Optional[str]): The unique identifier of the specific run or interaction. Defaults to `None`. |
| 169 | +- `usage` (Optional[dict]): A dictionary containing usage metrics, such as token counts and processing time. Defaults to `None`. |
| 170 | +- `run_status` (Optional[str]): The current status of the run (e.g., `'completed'`, `'in-progress'`, `'failed'`). Defaults to `None`. |
| 171 | +- `required_action` (Optional[`RequiredAction`]): An optional field indicating any required user action to proceed further. Defaults to `None`. |
| 172 | + |
| 173 | + |
| 174 | +#### `RequiredAction` |
| 175 | + |
| 176 | +`RequiredAction` is a data type representing an action required from the user to proceed with the interaction, typically involving the submission of tool outputs. |
| 177 | + |
| 178 | +Attributes: |
| 179 | +- `submit_tool_outputs` (List[`ToolCall`]): A list of `ToolCall` instances that the user needs to submit. |
| 180 | +- `type` (Literal["submit_tool_outputs"]): A literal string indicating the type of required action. Defaults to `"submit_tool_outputs"`. |
| 181 | + |
| 182 | +#### `Message` |
| 183 | + |
| 184 | +`Message` represents an individual message within a conversation thread between a user and an assistant. |
| 185 | + |
| 186 | +Attributes: |
| 187 | +- `id` (Optional[str]): The unique identifier of the message. Defaults to `None`. |
| 188 | +- `object` (Optional[str]): The type of the object, defaulting to `"thread.message"`. |
| 189 | +- `created_at` (Optional[int]): A timestamp indicating when the message was created. Defaults to `None`. |
| 190 | +- `thread_id` (Optional[str]): The unique identifier of the conversation thread. Defaults to `None`. |
| 191 | +- `role` (Optional[Literal["user", "assistant"]]): The role of the message sender, either `"user"` or `"assistant"`. Defaults to `None`. |
| 192 | +- `content` (Optional[Union[str, List[Union[`ImageFileContent`, `TextContent`, `RefusalContent`, `ImageUrlContent`]]]]): The content of the message, which can be a string or a list of content objects. Defaults to an empty list. |
| 193 | +- `assistant_id` (Optional[str]): The unique identifier of the assistant that generated the message. Defaults to `None`. |
| 194 | +- `run_id` (Optional[str]): The unique identifier of the specific run or interaction. Defaults to `None`. |
| 195 | +- `attachments` (List[`Attachment`]): A list of attachment objects associated with the message. Defaults to an empty list. |
| 196 | +- `metadata` (Optional[dict]): A dictionary containing additional metadata for the message. Defaults to an empty dictionary. |
| 197 | +- `required_action` (Optional[`RequiredAction`]): An optional field indicating any required action from the user to proceed further. Defaults to `None`. |
0 commit comments