Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

DurableAgent now supports stopWhen for controlling agent execution, matching AI SDK 6's ToolLoopAgent interface for portability.

Implementation

  • DurableAgent: Added stopWhen to constructor options and stream() method, accepting StopCondition<ToolSet> or arrays
  • Step tracking: Builds StepResult objects from tool calls/results to pass to condition evaluators
  • Safe parsing: Added safeJsonParse() to handle invalid JSON in tool inputs/outputs without crashing
  • Type exports: Re-exported StopCondition, StepResult, stepCountIs, hasToolCall from @workflow/ai for convenience

Usage

import { DurableAgent } from '@workflow/ai/agent';
import { stepCountIs, hasToolCall } from '@workflow/ai';

const agent = new DurableAgent({
  model: 'anthropic/claude-opus',
  tools: { getWeather: { /* ... */ } },
  stopWhen: stepCountIs(10), // Stop after 10 steps
});

// Or override per-stream
await agent.stream({
  messages: [{ role: 'user', content: 'What is the weather?' }],
  stopWhen: [stepCountIs(5), hasToolCall('getWeather')], // Stop on either condition
});

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/workflow/workflow/node_modules/.pnpm/next@15.5.4_@opentelemetry&#43;api@1.9.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/jest-worker/processChild.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

the DurableAgent class in workflow/ai package is meant to be very similar in interface to the ToolLoopAgent class in AI sdk 6. One of the things it's missing is the stopWhen property. Implement that and ensure it is compatible with the same options/types as the AI sdk version for easy portability


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2025

🦋 Changeset detected

Latest commit: 163acc9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Nov 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 7, 2025 8:15am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 7, 2025 8:15am
example-workflow Error Error Nov 7, 2025 8:15am
workbench-nitro-workflow Error Error Nov 7, 2025 8:15am
workbench-nuxt-workflow Error Error Nov 7, 2025 8:15am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 7, 2025 8:15am
workbench-vite-workflow Error Error Nov 7, 2025 8:15am
workflow-docs Ready Ready Preview Comment Nov 7, 2025 8:15am

Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants