Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wild-bananas-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@llamaindex/workflow": patch
"@llamaindex/anthropic": patch
---

fix: message delta visibility for anthropic
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a change set what we are fixing for workflow in this PR

Copy link
Author

@Kannav02 Kannav02 Oct 2, 2025

Choose a reason for hiding this comment

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

Oh I see, I was going through CONTRIBUTING.md and since this wasn't a feature, I thought that this wouldn't need a changeset, I'm sorry about it

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes. sure, that would be great!

9 changes: 9 additions & 0 deletions packages/providers/anthropic/src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@ export class Anthropic extends ToolCallLLM<
? part.delta.signature
: undefined;

if (part.type === "message_delta") {
yield {
raw: part,
delta: "",
options: {},
};
continue;
}

if (
part.type === "content_block_start" &&
part.content_block.type === "tool_use"
Expand Down
9 changes: 7 additions & 2 deletions packages/workflow/src/agent/agent-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type AgentResultData<O = JSONObject> = {
message: ChatMessage;
state?: AgentWorkflowState | undefined;
object?: O | undefined;
raw?: unknown;
};
export const stopAgentEvent = workflowEvent<AgentResultData, "llamaindex-stop">(
{
Expand All @@ -88,6 +89,7 @@ export type AgentStep = {
agentName: string;
response: ChatMessage;
toolCalls: AgentToolCall[];
raw: unknown;
};
export const agentStepEvent = workflowEvent<AgentStep>();

Expand Down Expand Up @@ -426,6 +428,7 @@ export class AgentWorkflow implements Workflow {
agentName: agent.name,
response: output.response,
toolCalls: output.toolCalls,
raw: output.raw,
}),
);

Expand All @@ -436,7 +439,7 @@ export class AgentWorkflow implements Workflow {
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<AgentStep>,
) => {
const { agentName, response, toolCalls } = event.data;
const { agentName, response, toolCalls, raw } = event.data;
const agent = this.agents.get(agentName);
if (!agent) {
throw new Error(
Expand All @@ -453,7 +456,7 @@ export class AgentWorkflow implements Workflow {
const agentOutput = {
response,
toolCalls: [],
raw: response,
raw,
currentAgentName: agentName,
};
const content = await agent.finalize(context.state, agentOutput);
Expand All @@ -472,6 +475,7 @@ export class AgentWorkflow implements Workflow {
result: content.response.content,
state: context.state,
object,
raw: content.raw ?? raw,
});
}

Expand Down Expand Up @@ -594,6 +598,7 @@ export class AgentWorkflow implements Workflow {
message: responseMessage,
result: output,
state: context.state,
raw,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/agent/function-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class FunctionAgent implements BaseWorkflowAgent {
let lastChunk: ChatResponseChunk | undefined;
const toolCalls: Map<string, AgentToolCall> = new Map();
for await (const chunk of responseStream) {
lastChunk = chunk;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

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

because in the following code snippet

    return {
      response: message,
      toolCalls: Array.from(toolCalls.values()),
      raw: lastChunk?.raw,
      currentAgentName: this.name,
    };

the raw chunk that is being returned takes the value from lastChunk.raw, in the earlier code, lastChunk was beind defined, but never assigned a value, thus lastChunk always had the value as undefined, so thats why i assigned it tha lastChunk that we see in the loop, sometime it could even be empty text, but even if its empty, it still sends metadata

response += chunk.delta;
ctx.sendEvent(
agentStreamEvent.with({
Expand Down