33interface llm {
44 // --- Roles, Error Codes, Finish Reasons ---
55
6+ /// Roles of the conversation
67 enum role {
8+ /// Instructions provided by the user
79 user ,
10+ /// Messages generated by the model
811 assistant ,
12+ /// Messages describing the system's rules
913 system ,
14+ /// Messages describing tool calls
1015 tool ,
1116 }
1217
18+ /// Possible error cases for LLM calls
1319 enum error-code {
20+ /// Invalid request parameters
1421 invalid-request ,
22+ /// Authentication failed
1523 authentication-failed ,
24+ /// Rate limit exceeded
1625 rate-limit-exceeded ,
26+ /// Internal error
1727 internal-error ,
28+ /// Unsupported operation
1829 unsupported ,
30+ /// Unknown error
1931 unknown ,
2032 }
2133
34+ /// Reasons for finishing a conversation
2235 enum finish-reason {
36+ /// The conversation finished
2337 stop ,
38+ /// Conversation finished because of reaching the maximum length
2439 length ,
40+ /// Conversation finished with request for calling tools
2541 tool-calls ,
42+ /// Conversation finished because of content filtering
2643 content-filter ,
44+ /// Conversation finished with an error
2745 error ,
46+ /// Other reason
2847 other ,
2948 }
3049
50+ /// Image detail levels
3151 enum image-detail {
3252 low ,
3353 high ,
@@ -36,153 +56,237 @@ interface llm {
3656
3757 // --- Message Content ---
3858
59+ /// Points to an image by an URL and an optional image detail level
3960 record image-url {
61+ /// The URL of the image
4062 url : string ,
63+ /// Level of detail of the image
4164 detail : option <image-detail >,
4265 }
4366
67+ /// Contains an inline image
4468 record image-source {
69+ /// Raw image data
4570 data : list <u8 >,
71+ /// MIME type of the image
4672 mime-type : string ,
73+ /// Level of detail of the image
4774 detail : option <image-detail >,
4875 }
4976
77+ /// Contains an image, either a remote or an inlined one
5078 variant image-reference {
79+ /// A remote image
5180 url (image-url ),
81+ /// An inlined image
5282 inline (image-source ),
5383 }
5484
85+ /// One part of the conversation
5586 variant content-part {
87+ /// Text content
5688 text (string ),
89+ /// Image content
5790 image (image-reference ),
5891 }
5992
93+ /// A message in the conversation
6094 record message {
95+ /// Role of this message
6196 role : role ,
97+ /// Name of the sender
6298 name : option <string >,
99+ /// Content of the message
63100 content : list <content-part >,
64101 }
65102
66103 // --- Tooling ---
67104
105+ /// Describes a tool callable by the LLM
68106 record tool-definition {
107+ /// Name of the tool
69108 name : string ,
109+ /// Description of the tool
70110 description : option <string >,
111+ /// Schema of the tool's parameters - usually a JSON schema
71112 parameters-schema : string ,
72113 }
73114
115+ /// Describes a tool call request
74116 record tool-call {
117+ /// Call identifier
75118 id : string ,
119+ /// Name of the tool
76120 name : string ,
121+ /// Arguments of the tool call
77122 arguments-json : string ,
78123 }
79124
125+ /// Describes a successful tool call
80126 record tool-success {
127+ /// Call identifier
81128 id : string ,
129+ /// Name of the tool
82130 name : string ,
131+ /// Result of the tool call in JSON
83132 result-json : string ,
133+ /// Execution time of the tool call in milliseconds
84134 execution-time-ms : option <u32 >,
85135 }
86136
137+ /// Describes a failed tool call
87138 record tool-failure {
139+ /// Call identifier
88140 id : string ,
141+ /// Name of the tool
89142 name : string ,
143+ /// Error message of the tool call
90144 error-message : string ,
145+ /// Error code of the tool call
91146 error-code : option <string >,
92147 }
93148
149+ /// Result of a tool call
94150 variant tool-result {
151+ /// The tool call succeeded
95152 success (tool-success ),
153+ /// The tool call failed
96154 error (tool-failure ),
97155 }
98156
99157 // --- Configuration ---
100158
159+ /// Simple key-value pair
101160 record kv {
102161 key : string ,
103162 value : string ,
104163 }
105164
165+ /// LLM configuration
106166 record config {
167+ /// The model to use
107168 model : string ,
169+ /// Temperature
108170 temperature : option <f32 >,
171+ /// Maximum number of tokens
109172 max-tokens : option <u32 >,
173+ /// A sequence where the model stops generating tokens
110174 stop-sequences : option <list <string >>,
175+ /// List of available tools
111176 tools : list <tool-definition >,
177+ /// Tool choice policy
112178 tool-choice : option <string >,
179+ /// Additional LLM provider specific key-value pairs
113180 provider-options : list <kv >,
114181 }
115182
116183 // --- Usage / Metadata ---
117184
185+ /// Token usage statistics
118186 record usage {
187+ /// Number of input tokens used
119188 input-tokens : option <u32 >,
189+ /// Number of output tokens generated
120190 output-tokens : option <u32 >,
191+ /// Total number of tokens used
121192 total-tokens : option <u32 >,
122193 }
123194
195+ /// Metadata about an LLM response
124196 record response-metadata {
197+ /// Reason for finishing the conversation
125198 finish-reason : option <finish-reason >,
199+ /// Usage statistics
126200 usage : option <usage >,
201+ /// Provider-specific ID
127202 provider-id : option <string >,
203+ /// Timestamp
128204 timestamp : option <string >,
205+ /// Provider-specific additional metadata in JSON
129206 provider-metadata-json : option <string >,
130207 }
131208
209+ /// Response from an LLM
132210 record complete-response {
211+ /// Response ID
133212 id : string ,
213+ /// Result contents
134214 content : list <content-part >,
215+ /// Tool call requests
135216 tool-calls : list <tool-call >,
217+ /// Response metadata
136218 metadata : response-metadata ,
137219 }
138220
139221 // --- Error Handling ---
140222
223+ /// LLM error
141224 record error {
225+ /// Error code
142226 code : error-code ,
227+ /// Error message
143228 message : string ,
229+ /// More details in JSON, in a provider-specific format
144230 provider-error-json : option <string >,
145231 }
146232
147233 // --- Chat Response Variants ---
148234
235+ /// One resulting event in an LLM conversation
149236 variant chat-event {
237+ /// A response in the conversation
150238 message (complete-response ),
239+ /// A request for calling one or more tools
151240 tool-request (list <tool-call >),
241+ /// An error in the conversation
152242 error (error ),
153243 }
154244
155245 // --- Streaming ---
156246
247+ /// Changes in a streaming conversation
157248 record stream-delta {
249+ /// New content parts
158250 content : option <list <content-part >>,
251+ /// New tool calls
159252 tool-calls : option <list <tool-call >>,
160253 }
161254
255+ /// Event in a streaming conversation
162256 variant stream-event {
257+ /// New incoming response content or tool call requests
163258 delta (stream-delta ),
259+ /// Converstation finished
164260 finish (response-metadata ),
261+ /// Conversation failed
165262 error (error ),
166263 }
167264
265+ /// Represents an ongoing streaming LLM conversation
168266 resource chat-stream {
267+ /// Polls for the next chunk of stream events
169268 get-next : func () -> option <list <stream-event >>;
269+ /// Blocks until the next chunk of stream events is available
170270 blocking-get-next : func () -> list <stream-event >;
171271 }
172272
173273 // --- Core Functions ---
174274
275+ /// Make a single call to the LLM. Continue the conversation with `continue` if needed.
175276 send : func (
176277 messages : list <message >,
177278 config : config
178279 ) -> chat-event ;
179280
281+ /// Continues a previous conversation initiated by `send` or a previous `continue` , by sending the updated
282+ /// set of messages, and possible set of tool call results.
180283 continue : func (
181284 messages : list <message >,
182285 tool-results : list <tuple <tool-call , tool-result >>,
183286 config : config
184287 ) -> chat-event ;
185288
289+ /// Makes a single call to the LLM and gets back a streaming API to receive the response in chunks.
186290 %stream : func (
187291 messages : list <message >,
188292 config : config
0 commit comments