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

lastStep undefined issue #4147

Open
tjk opened this issue Dec 18, 2024 · 3 comments
Open

lastStep undefined issue #4147

tjk opened this issue Dec 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tjk
Copy link

tjk commented Dec 18, 2024

Description

Still need to understand why this is happening... but there seems to at least be a problem in the code.

Comment + check for nullish lastStep here:

// from last step (when there are errors there may be no last step)
const lastStep = recordedSteps[recordedSteps.length - 1];
if (lastStep) {

but then accessed without care here:

toolCalls: lastStep.toolCalls,

Produces this stack trace:

Cause: TypeError: Cannot read properties of undefined (reading 'toolCalls')
    at Object.flush (turbopack://[project]/node_modules/.pnpm/ai@4.0.20_react@19.0.0-rc-45804af1-20241021_zod@3.23.8/node_modules/ai/core/generate-text/stream-text.ts:571:21)
  569 |             toolCalls: lastStep.toolCalls,
  570 |             toolResults: lastStep.toolResults,
> 571 |             request: lastStep.request ?? {},
      |                     ^
  572 |             response: lastStep.response,
  573 |             warnings: lastStep.warnings,

AI provider

Anthropic. Don't get this error With OpenAI, I think. Probably something to do with tools declaration, but would be nice to get better feedback than just that stack above.

@tjk tjk added the bug Something isn't working label Dec 18, 2024
@tjk
Copy link
Author

tjk commented Dec 18, 2024

It looks like this issue might be related (and what I'm running into): #3422

@lgrammel
Copy link
Collaborator

lgrammel commented Dec 19, 2024

Can you share the code you use to call streamText?

Anthropic does not support structured outputs with streamText (we use tool calls with streamObject/generateObject), so this might not work with Anthropic.

@Taofeeq-deru
Copy link

I'm getting this same error, using steamText not steamObject, with openai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants