Skip to content

Conversation

@TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Nov 18, 2025

Updated DurableAgent#stream() to return a messages array containing the full conversation history.

What changed?

  • Modified DurableAgent#stream() to return an object with a messages property containing the complete conversation history
  • Updated the stream text iterator to return the final conversation prompt
  • Added documentation and examples showing how to use the returned messages for multi-turn conversations
  • Enhanced the documentation to explain that returned messages include initial messages, assistant responses, and tool results

How to test?

  1. Create a DurableAgent instance with tools
  2. Call agent.stream() with initial messages
  3. Verify the returned object contains a messages array with the full conversation
  4. Use the returned messages in a subsequent agent.stream() call to continue the conversation
  5. Check that the conversation history is properly maintained
const agent = new DurableAgent({
  model: 'anthropic/claude-haiku-4.5',
  tools: { /* tool definitions */ }
});

// First turn
const { messages } = await agent.stream({
  messages: [{ role: 'user', content: 'Find me some laptops' }]
});

// Second turn using returned messages
const result = await agent.stream({
  messages: [
    ...messages,
    { role: 'user', content: 'Which one has the best battery life?' }
  ]
});

console.log(result.messages); // Full conversation history

Why make this change?

This change makes it easier to build multi-turn conversations with DurableAgent by providing access to the complete conversation history. Previously, developers had to manually track and maintain the conversation state between interactions. Now, the agent returns the full message history, which can be directly used in subsequent calls, simplifying the implementation of conversational agents that maintain context across multiple interactions.

@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

🦋 Changeset detected

Latest commit: a71caa8

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 18, 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 22, 2025 6:37am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 22, 2025 6:37am
example-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-astro-workflow Error Error Nov 22, 2025 6:37am
workbench-express-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-hono-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-nitro-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workbench-vite-workflow Ready Ready Preview Comment Nov 22, 2025 6:37am
workflow-docs Ready Ready Preview Comment Nov 22, 2025 6:37am

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

const toolResult = await tool.execute(input.value, {
toolCallId: toolCall.toolCallId,
// TODO: pass the proper messages to the tool
// TODO: pass the proper messages to the tool (we'd need to pass them through the iterator)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym by that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From claude, but I guess it's saying that each yield from the iterator needs to pass the current state of messages as well as the toolCalls. This part isn't currently being provided here anyways so I'll save figuring that part out for a later PR.

}
}

return conversationPrompt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt?

Suggested change
return conversationPrompt;
return { messages: conversationPrompt};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with it, but it's also not really important because this is not the public facing API, we could easily refactor later if we need to return more information.

Copy link
Collaborator

@pranaygp pranaygp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some nits and docs comments but otherwise lgtm

@TooTallNate TooTallNate changed the title Make DurableAgent#stream() return a messages array [ai] Make DurableAgent#stream() return a messages array Nov 19, 2025
@TooTallNate TooTallNate force-pushed the 11-18-make_durableagent_stream_return_a_messages_array branch from a8c9d48 to 2340289 Compare November 20, 2025 08:21
Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Build Fix:

The if (!input?.success) block is missing a closing brace, causing a syntax error that prevents TypeScript compilation from completing. The try statement on line 218 cannot be parsed without the closing brace.

View Details
📝 Patch Details
diff --git a/packages/ai/src/agent/durable-agent.ts b/packages/ai/src/agent/durable-agent.ts
index 9b19067..0a3dd43 100644
--- a/packages/ai/src/agent/durable-agent.ts
+++ b/packages/ai/src/agent/durable-agent.ts
@@ -216,6 +216,7 @@ async function executeTool(
     throw new Error(
       `Invalid input for tool "${toolCall.toolName}": ${input?.error?.message}`
     );
+  }
 
   try {
     const toolResult = await tool.execute(input.value, {

Analysis

Missing closing brace in TypeScript async function causes syntax error

What fails: TypeScript compiler fails on packages/ai/src/agent/durable-agent.ts due to missing closing brace in the executeTool function

How to reproduce:

cd packages/ai
npx tsc --noEmit

Result:

src/agent/durable-agent.ts(254,1): error TS1005: '}' expected.

Root cause: The if (!input?.success) block at line 215 was missing a closing brace before the try statement at line 218, causing a syntax error that prevents TypeScript compilation.

Fix on Vercel

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Build Fix:

The if (!input?.success) block is missing its closing brace }, causing TypeScript to expect the brace at the start of the following try block instead. This syntax error prevents the entire package from compiling.

View Details
📝 Patch Details
diff --git a/packages/ai/src/agent/durable-agent.ts b/packages/ai/src/agent/durable-agent.ts
index 9b19067..0a3dd43 100644
--- a/packages/ai/src/agent/durable-agent.ts
+++ b/packages/ai/src/agent/durable-agent.ts
@@ -216,6 +216,7 @@ async function executeTool(
     throw new Error(
       `Invalid input for tool "${toolCall.toolName}": ${input?.error?.message}`
     );
+  }
 
   try {
     const toolResult = await tool.execute(input.value, {

Analysis

Missing closing brace in executeTool function causes TypeScript compilation failure

What fails: TypeScript compiler fails to parse src/agent/durable-agent.ts due to a missing closing brace for the if (!input?.success) conditional block in the executeTool function.

How to reproduce:

cd packages/ai && npm run build

Result:

src/agent/durable-agent.ts(254,1): error TS1005: '}' expected.

What was wrong: The if (!input?.success) block on line 216-220 was missing its closing brace }. The try block immediately following it on line 222 appeared without the if block being properly terminated, causing a syntax error.

Fix on Vercel

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Build Fix:

The if (!input?.success) conditional block was missing a closing brace }, causing the TypeScript compiler to fail with a syntax error at the end of the file.

View Details
📝 Patch Details
diff --git a/packages/ai/src/agent/durable-agent.ts b/packages/ai/src/agent/durable-agent.ts
index 9b19067..0a3dd43 100644
--- a/packages/ai/src/agent/durable-agent.ts
+++ b/packages/ai/src/agent/durable-agent.ts
@@ -216,6 +216,7 @@ async function executeTool(
     throw new Error(
       `Invalid input for tool "${toolCall.toolName}": ${input?.error?.message}`
     );
+  }
 
   try {
     const toolResult = await tool.execute(input.value, {

Analysis

Missing closing brace in executeTool function causes TypeScript compilation failure

What fails: TypeScript compiler fails on @workflow/ai package build due to missing closing brace in src/agent/durable-agent.ts

How to reproduce:

cd packages/ai && pnpm run build

Result (before fix):

src/agent/durable-agent.ts(254,1): error TS1005: '}' expected.
 ELIFECYCLE  Command failed with exit code 2.

Root cause: The if (!input?.success) block at line 216 was missing its closing brace, causing the TypeScript parser to expect a closing brace at the end of the file (line 254).

Fix applied: Added missing closing brace } after the error throw statement in the if (!input?.success) block to properly close the conditional block before the try statement.

Fix on Vercel

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.

3 participants