chore: bump @llamaindex/workflow-core in @llamaindex/workflow package (#2181)

This commit is contained in:
Thuc Pham
2025-08-27 16:30:09 +07:00
committed by GitHub
parent 001a5159cf
commit 1995b38660
7 changed files with 64 additions and 46 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/workflow": patch
---
bump @llamaindex/workflow-core in workflow package
+4 -4
View File
@@ -22,7 +22,7 @@ const { withState, getContext } = createStatefulMiddleware(() => ({
const jokeFlow = withState(createWorkflow());
// Define handlers for each step
jokeFlow.handle([startEvent], async (event) => {
jokeFlow.handle([startEvent], async (context, event) => {
// Prompt the LLM to write a joke
const prompt = `Write your best joke about ${event.data}. Write the joke between <joke> and </joke> tags.`;
const response = await llm.complete({ prompt });
@@ -34,7 +34,7 @@ jokeFlow.handle([startEvent], async (event) => {
return jokeEvent.with({ joke: joke });
});
jokeFlow.handle([jokeEvent], async (event) => {
jokeFlow.handle([jokeEvent], async (context, event) => {
// Prompt the LLM to critique the joke
const prompt = `Give a thorough critique of the following joke. If the joke needs improvement, put "IMPROVE" somewhere in the critique: ${event.data.joke}`;
const response = await llm.complete({ prompt });
@@ -50,9 +50,9 @@ jokeFlow.handle([jokeEvent], async (event) => {
return resultEvent.with({ joke: event.data.joke, critique: response.text });
});
jokeFlow.handle([critiqueEvent], async (event) => {
jokeFlow.handle([critiqueEvent], async (context, event) => {
// Keep track of the number of iterations
const state = getContext().state;
const state = context.state;
state.numIterations++;
// Write a new joke based on the previous joke and critique
+1 -1
View File
@@ -49,6 +49,6 @@
"zod-to-json-schema": "^3.24.6"
},
"dependencies": {
"@llamaindex/workflow-core": "^1.0.0"
"@llamaindex/workflow-core": "^1.3.0"
}
}
+8 -4
View File
@@ -1,4 +1,7 @@
import { getContext, type WorkflowEventData } from "@llamaindex/workflow-core";
import {
type WorkflowContext,
type WorkflowEventData,
} from "@llamaindex/workflow-core";
import {
AgentWorkflow,
startAgentEvent,
@@ -71,9 +74,10 @@ function createWorkflowForStepHandler(
export const agentHandler = (
params: Omit<StepHandlerParams, "workflowContext">,
) => {
return async (event: WorkflowEventData<unknown>) => {
const context = getContext();
return async (
context: WorkflowContext,
event: WorkflowEventData<unknown>,
) => {
const workflow = createWorkflowForStepHandler({
...params,
workflowContext: context,
+41 -31
View File
@@ -8,7 +8,6 @@ import { stringifyJSONToMessageContent } from "@llamaindex/core/utils";
import { consoleLogger, emptyLogger, type Logger } from "@llamaindex/env";
import {
createWorkflow,
getContext,
workflowEvent,
type Handler,
type Workflow,
@@ -16,7 +15,10 @@ import {
type WorkflowEvent,
type WorkflowEventData,
} from "@llamaindex/workflow-core";
import { createStatefulMiddleware } from "@llamaindex/workflow-core/middleware/state";
import {
createStatefulMiddleware,
type StatefulContext,
} from "@llamaindex/workflow-core/middleware/state";
import { z } from "zod";
import type { AgentWorkflowState, BaseWorkflowAgent } from "./base";
import {
@@ -339,9 +341,10 @@ export class AgentWorkflow implements Workflow {
}
private handleInputStep = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<AgentInputData>,
) => {
const { state } = this.stateful.getContext();
const { state } = context;
const { userInput, chatHistory } = event.data;
const memory = state.memory;
if (chatHistory) {
@@ -375,7 +378,10 @@ export class AgentWorkflow implements Workflow {
});
};
private setupAgent = async (event: WorkflowEventData<AgentInput>) => {
private setupAgent = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<AgentInput>,
) => {
const currentAgentName = event.data.currentAgentName;
const agent = this.agents.get(currentAgentName);
if (!agent) {
@@ -396,16 +402,19 @@ export class AgentWorkflow implements Workflow {
});
};
private runAgentStep = async (event: WorkflowEventData<AgentSetup>) => {
const { sendEvent } = this.stateful.getContext();
private runAgentStep = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<AgentSetup>,
) => {
const { sendEvent } = context;
const agent = this.agents.get(event.data.currentAgentName);
if (!agent) {
throw new Error("No valid agent found");
}
const output = await agent.takeStep(
this.stateful.getContext(),
this.stateful.getContext().state,
context,
context.state,
event.data.input,
agent.tools,
);
@@ -421,7 +430,10 @@ export class AgentWorkflow implements Workflow {
sendEvent(agentOutputEvent.with(output));
};
private parseAgentOutput = async (event: WorkflowEventData<AgentStep>) => {
private parseAgentOutput = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<AgentStep>,
) => {
const { agentName, response, toolCalls } = event.data;
const agent = this.agents.get(agentName);
if (!agent) {
@@ -442,15 +454,12 @@ export class AgentWorkflow implements Workflow {
raw: response,
currentAgentName: agentName,
};
const content = await agent.finalize(
this.stateful.getContext().state,
agentOutput,
);
const content = await agent.finalize(context.state, agentOutput);
return stopAgentEvent.with({
message: content.response,
result: content.response.content,
state: this.stateful.getContext().state,
state: context.state,
});
}
@@ -460,8 +469,11 @@ export class AgentWorkflow implements Workflow {
});
};
private executeToolCalls = async (event: WorkflowEventData<ToolCalls>) => {
const { sendEvent } = getContext();
private executeToolCalls = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<ToolCalls>,
) => {
const { sendEvent } = context;
const { agentName, toolCalls } = event.data;
const agent = this.agents.get(agentName);
if (!agent) {
@@ -507,6 +519,7 @@ export class AgentWorkflow implements Workflow {
};
private processToolResults = async (
context: StatefulContext<AgentWorkflowState>,
event: WorkflowEventData<ToolResults>,
) => {
const { agentName, results } = event.data;
@@ -517,10 +530,7 @@ export class AgentWorkflow implements Workflow {
throw new Error(`Agent ${agentName} not found`);
}
await agent.handleToolCallResults(
this.stateful.getContext().state,
results,
);
await agent.handleToolCallResults(context.state, results);
const directResult = results.find(
(r: AgentToolCallResult) => r.returnDirect,
@@ -542,22 +552,22 @@ export class AgentWorkflow implements Workflow {
currentAgentName: agent.name,
};
await agent.finalize(this.stateful.getContext().state, agentOutput);
await agent.finalize(context.state, agentOutput);
if (isHandoff) {
const nextAgentName = this.stateful.getContext().state.nextAgentName;
const nextAgentName = context.state.nextAgentName;
this.logger.log(
`[Agent ${agentName}]: Handoff to ${nextAgentName}: ${directResult.toolOutput.result}`,
);
if (nextAgentName) {
this.stateful.getContext().state.currentAgentName = nextAgentName;
this.stateful.getContext().state.nextAgentName = null;
context.state.currentAgentName = nextAgentName;
context.state.nextAgentName = null;
const messages = await this.stateful
.getContext()
.state.memory.getLLM(this.agents.get(nextAgentName)?.llm);
const messages = await context.state.memory.getLLM(
this.agents.get(nextAgentName)?.llm,
);
this.logger.log(`[Agent ${nextAgentName}]: Starting agent`);
@@ -571,14 +581,14 @@ export class AgentWorkflow implements Workflow {
return stopAgentEvent.with({
message: responseMessage,
result: output,
state: this.stateful.getContext().state,
state: context.state,
});
}
// Continue with another agent step
const messages = await this.stateful
.getContext()
.state.memory.getLLM(this.agents.get(agent.name)?.llm);
const messages = await context.state.memory.getLLM(
this.agents.get(agent.name)?.llm,
);
return agentInputEvent.with({
input: messages,
currentAgentName: agent.name,
-1
View File
@@ -1,5 +1,4 @@
export * from "@llamaindex/workflow-core";
export * from "@llamaindex/workflow-core/middleware/snapshot";
export * from "@llamaindex/workflow-core/middleware/state";
export * from "@llamaindex/workflow-core/stream/run";
export { zodEvent } from "@llamaindex/workflow-core/util/zod";
+5 -5
View File
@@ -1930,8 +1930,8 @@ importers:
packages/workflow:
dependencies:
'@llamaindex/workflow-core':
specifier: ^1.0.0
version: 1.0.0(@modelcontextprotocol/sdk@1.13.0)(hono@4.7.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)
specifier: ^1.3.0
version: 1.3.0(@modelcontextprotocol/sdk@1.13.0)(hono@4.7.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)
zod:
specifier: ^3.25.67
version: 3.25.76
@@ -4273,8 +4273,8 @@ packages:
'@llamaindex/chat-ui-docs@0.1.0':
resolution: {integrity: sha512-+DwnLSWDOJk2d6lGDhLYtmpeGHho4AjKE2aQMz8J0ZF29RlSqp/Z5HmhQoYIjK0neIM1S9eF7ubuM1zpVpZqrg==}
'@llamaindex/workflow-core@1.0.0':
resolution: {integrity: sha512-pMQk89x11wvJu+uNHqB9gIZ1Ww069CikgltNcuxo4Bi1ajzrvScsu3H+3VS1XmkinKxhQjHjT+BJdObfWBfNCQ==}
'@llamaindex/workflow-core@1.3.0':
resolution: {integrity: sha512-5HsIuDpeiXZUTsy5nJ+F7PUnStQdzEoEmc6/0IDlL4eqK3svBEitbOGlxCTPMYasoVni2XsEL1ox1QtVrtrzpw==}
peerDependencies:
'@modelcontextprotocol/sdk': ^1.7.0
hono: ^4.7.4
@@ -17211,7 +17211,7 @@ snapshots:
'@llamaindex/chat-ui-docs@0.1.0': {}
'@llamaindex/workflow-core@1.0.0(@modelcontextprotocol/sdk@1.13.0)(hono@4.7.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)':
'@llamaindex/workflow-core@1.3.0(@modelcontextprotocol/sdk@1.13.0)(hono@4.7.7)(next@15.3.3(@opentelemetry/api@1.9.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(p-retry@6.2.1)(zod@3.25.76)':
optionalDependencies:
'@modelcontextprotocol/sdk': 1.13.0
hono: 4.7.7