Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js/ai): Adds "restart" for tool interrupts with flexible resuming. #1693

Merged
merged 8 commits into from
Jan 31, 2025

Conversation

mbleigh
Copy link
Collaborator

@mbleigh mbleigh commented Jan 29, 2025

Implements "restarts" on top of interrupts. Usage:

const sendText = ai.defineTool({
  name: 'sendText',
  description: 'send a text message',
  inputSchema: z.object({to: z.array(z.string()), message: z.string()}),
}, async (input, {context, interrupt, resumed}) => {
  // if not confirmed
  if (!resumed) interrupt({message: "Does this text look good to send?");
  sendTextMessage(context.auth.uid, input);
});

let response = await ai.generate({
  prompt: "Send a text to mom telling her I'll be late.",
  tools: [sendText],
});

if (interrupts.length) {
  const revisedMessage = await confirmOrReviseMessage(interrupts['0]);
  response = await ai.generate({
    resume: {restart: sendText.restart(interrupts[0], true, {replaceInput: revisedMessage});
  });
}

Checklist (if applicable):

@mbleigh mbleigh requested a review from pavelgj January 29, 2025 20:19
@mbleigh mbleigh marked this pull request as ready for review January 30, 2025 05:43
@mbleigh
Copy link
Collaborator Author

mbleigh commented Jan 30, 2025

This is ready for review, the build errors are unrelated to my code.

@mbleigh mbleigh merged commit b52ec84 into main Jan 31, 2025
4 checks passed
@mbleigh mbleigh deleted the mb/restarts branch January 31, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants