AG Studio is provider-agnostic and does not bundle a connection to any LLM. To use the AI assistant, you must implement the AgAiAssistant interface, which translates between AG Studio's request format and your chosen AI provider.
The AgAiAssistant Interface Copy Link
The adapter is a plain object with one required method - executeTurn.
Execute a single turn of conversation with the AI. A turn consists of sending input and receiving a streamed response.
|
executeTurn Copy Link
executeTurn is called every time Studio needs an AI response. It receives an AgAiRequest and must return an AgAiResponseHandler synchronously. The handler provides both a real-time stream and a completion promise.
The Assistant Request Copy Link
Each call to executeTurn receives a request containing everything the AI needs.
Conversation history to send to the AI, providing context. |
System instructions for this specific turn, overriding defaults. |
Tools available for the AI to use during this turn. |
Strategy for how the AI should choose tools. |
Output format configuration controlling response structure. |
The LLM Response Copy Link
executeTurn must return an AgAiResponseHandler - an object with a stream and a complete promise.
Async iterable of stream events for real-time updates. Events are yielded as they arrive from the AI provider.
|
Promise that resolves when the response is fully complete. Contains the final, consolidated response data.
|
Stream Event Types Copy Link
The stream yields AgAiStreamEvent values. Each event has a type and event discriminator:
| Type | Event | Description |
|---|---|---|
status | created | Response object has been created by the provider. |
status | in_progress | The AI is actively generating. |
status | completed | Generation finished. The event includes the final AgAiResponse. |
status | failed | Generation failed. |
error | api, network, timeout, etc. | An error occurred. Includes code and message. |
item | added | A new output item (message, tool call, reasoning) started. |
item | done | An output item finished. |
part | added | A content part within an item started (e.g. a text segment). |
part | done | A content part finished. |
delta | update | Incremental content - a text or argument chunk to append. |
delta | done | Final content for a part. |
Tool Call Handling Copy Link
The adapter does not execute tools. Its only responsibility is to:
- Pass
AgToolSchema[]definitions to the LLM (viarequest.tools). - Relay tool call output items from the LLM response back through the stream.
- Studio intercepts tool calls, executes them internally, and feeds results back as
function_call_outputitems in subsequent turns.
This means your adapter never needs to know what view_schema or configure_widget actually do - Studio handles all of that.
Interface Reference Copy Link
Unique identifier for this response. |
Timestamp when the response was created (milliseconds since epoch). |
Error details if the response failed, null otherwise. |
Details about why the response was incomplete. Present when the AI couldn't fully complete its response.
|
Output items produced by the AI (messages, tool calls, reasoning). |
Current status of the response. |
Tool name. |
Human-readable description for the LLM. |
JSON Schema describing the tool's parameters. |
Next Steps Copy Link
- Configuration - Wire up the adapter and show the AI panel.