You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When I've got a set of multiple interrupt definitions, I need a way to map from the interrupt result to a specific interrupt definition so that I can get a fully-formed response to feed into ai.generate(). The respond to interrupts sample hardcodes the single askQuestion interrupt, which doesn't work where there are multiple possible interrupts for the LLM to choose from.
Describe alternatives you've considered
The name of the interrupt used is available for each interrupt in the array returned by the ai.generate method via interrupts[i].toolRequest.name. However, you can't compare that to a list of available tools (including interrupts) because the value of each tool's name property is 'asyncFn'.
I can use the registry.actionsById property to look up an interrupt:
The problem with that is the the IDE now complains when I call the respond method: Property 'respond' does not exist on type 'Action<ZodTypeAny, ZodTypeAny, ZodTypeAny, ActionRunOptions<ZodTypeAny>>'.ts(2339)
Of course, I could build my own map of interrupt names to interrupt definitions, but that seems redundant, since genkit is tracking this data itself.
I'd like a supported way to look up an interrupt by name so that I can avoid these issues, please and thank you!
Describe the solution you'd like
If tool.name returned a reasonable value or the actionsById map was available or even if I could get what I needed from listActions(), any of those would be fine.
If I ran the zoo, I think I'd prefer an API that didn't need a specific interrupt definition to respond to an interrupt; I'd rather pass in a list of interrupt definitions, interrupts and results as part of my resumption call to at.generate(). Second place would be something like ai.registration.interruptByName map or method. But really anything that doesn't pollute the code too much and that doesn't raise errors in the IDE works for me.
You actually don't need an interrupt definition to respond to an interrupt, the respond helper is just a convenience for constructing a correctly-named toolResponse part. You can also do:
constresponse=ai.generate({// ...tools: [someInterrupt,anotherInterrupt,aThirdInterrupt]});constresponses=response.interrupts.map(interrupt=>({toolResponse: {name: interrupt.toolRequest.name,ref: interrupt.toolRequest.ref,output: {...},// populate this however you'd like}}));// second generationconstsecondResponse=awaitai.generate({messages: response.messages,resume: {respond: responses},})
Does that help? Probably ought to document that the helpers are just sugaring over tool responses...
that's super helpful; I can do that on the client side and avoid even sending the interrupts back to the server from the client as context. if that made it into the docs, I'd feel safer depending on it in my code.
that said, if you're going to provide a helper on the server-side, there should be a good way to call it in the face of multiple interrupts, so I think the original issue stands.
Is your feature request related to a problem? Please describe.
When I've got a set of multiple interrupt definitions, I need a way to map from the interrupt result to a specific interrupt definition so that I can get a fully-formed response to feed into
ai.generate()
. The respond to interrupts sample hardcodes the singleaskQuestion
interrupt, which doesn't work where there are multiple possible interrupts for the LLM to choose from.Describe alternatives you've considered
The name of the interrupt used is available for each interrupt in the array returned by the
ai.generate
method viainterrupts[i].toolRequest.name
. However, you can't compare that to a list of available tools (including interrupts) because the value of each tool'sname
property is'asyncFn'
.I can use the
registry.actionsById
property to look up an interrupt:Unfortunately, the use of this map yields an error in the IDE:
'Property 'actionsById' is private and only accessible within class 'Registry'.ts(2341)'
I can use the result of
ai.registry.listActions()
:The problem with that is the the IDE now complains when I call the
respond
method:Property 'respond' does not exist on type 'Action<ZodTypeAny, ZodTypeAny, ZodTypeAny, ActionRunOptions<ZodTypeAny>>'.ts(2339)
Of course, I could build my own map of interrupt names to interrupt definitions, but that seems redundant, since genkit is tracking this data itself.
I'd like a supported way to look up an interrupt by name so that I can avoid these issues, please and thank you!
Describe the solution you'd like
If
tool.name
returned a reasonable value or theactionsById
map was available or even if I could get what I needed fromlistActions()
, any of those would be fine.If I ran the zoo, I think I'd prefer an API that didn't need a specific interrupt definition to respond to an interrupt; I'd rather pass in a list of interrupt definitions, interrupts and results as part of my resumption call to
at.generate()
. Second place would be something likeai.registration.interruptByName
map or method. But really anything that doesn't pollute the code too much and that doesn't raise errors in the IDE works for me.fyi: @mbleigh
The text was updated successfully, but these errors were encountered: