consider a rust handler fn with two args:
#[local]
async fn toggle_entry_completion(
&mut self,
entry_id: u64,
completed: bool,
) -> Result<Entry, String> {
// Implementation goes here
}
this gets transformed into wit:
// Function signature for: toggle-entry-completion (local)
record toggle-entry-completion-signature-local {
target: address,
entry-id: u64,
completed: bool,
returning: result<entry, string>
}
and eventually into an HPMRequest variant:
enum HPMRequest {
...
ToggleEntryCompletion(u64, bool),
...
}
the problem is that we want llms to be able to consume these apis as easily as possible. the way we do that is we parse the wit into json. that gives:
{
"definition": {
"properties": {
"completed": "bool",
"entry_id": "u64",
"returning": {
"err": "string",
"ok": "Entry",
"type": "result"
},
"target": "Address"
},
"type": "object"
},
"documentation": "Function signature for: toggle-entry-completion (local)",
"name": "ToggleEntryCompletionSignatureLocal",
"process_name": "todo"
}
which is problematic for two reasons.
- since there are two arguments and the
recordis parsed into a json object, we don't maintain ordering. if you look at the HPMRequest we will need the llm to eventually send, it is a tuple: strictly ordered! therefore, we must use a json array, not a json object. - it makes life harder for the llm when we should be making life easier. sure llms will get better, but if we want reliable performance we should make parsing as easy as possible for the llm.
thus, we should change the wit form to, e.g.
// Function signature for: toggle-entry-completion (local)
record toggle-entry-completion-signature-local {
target: address,
// (entry-id: u64, completed: bool)
args: tuple<u64, bool>,
returning: result<entry, string>
}
which will result in a parsed json properties that looks like
{
"definition": {
"properties": {
"args": [
"u64",
"bool"
],
"returning": {
"err": "string",
"ok": "Entry",
"type": "result"
},
"target": "Address"
},
"type": "object"
},
"documentation": "Function signature for: toggle-entry-completion (local)",
"name": "ToggleEntryCompletionSignatureLocal",
"process_name": "todo"
}
(note there will also likely be another "documentation" field, but this is a by-hand example).
we can then either pass this to an llm and tell it to pull out the "args" or else manually parse in code and serve it up exactly as the llm needs it, i.e.:
{
"ToggleEntryCompletion": [
"u64",
"bool"
]
}