Skip to content

Commit

Permalink
feat: make AgentWorkflow llm param optional (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn authored Mar 10, 2025
1 parent 6f8b68a commit c1b5be5
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .changeset/shiny-camels-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"llamaindex": patch
"@llamaindex/workflow": patch
---

feat: make AgentWorkflow llm param optional
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Lastly, we run the workflow. The `.run()` method is async, so we use await here
Optionally, you can choose to use a shared context between steps by specifying a context type when creating the workflow. Here's an example where multiple steps access a shared state:

```typescript
import { HandlerContext } from "@llamaindex/workflow";
import { HandlerContext } from "llamaindex";

type MyContextData = {
query: string;
Expand Down
2 changes: 1 addition & 1 deletion examples/agentworkflow/multiple_agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2. TemperatureConverterAgent - Converts the temperature from Fahrenheit to Celsius
*/
import { OpenAI } from "@llamaindex/openai";
import { StopEvent } from "@llamaindex/workflow";
import {
AgentInput,
AgentOutput,
Expand All @@ -14,6 +13,7 @@ import {
AgentWorkflow,
FunctionAgent,
FunctionTool,
StopEvent,
} from "llamaindex";
import { z } from "zod";

Expand Down
5 changes: 3 additions & 2 deletions examples/agentworkflow/single_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
* This example shows how to use AgentWorkflow as a single agent with tools
*/
import { OpenAI } from "@llamaindex/openai";
import { AgentWorkflow } from "llamaindex";
import { AgentWorkflow, Settings } from "llamaindex";
import { getWeatherTool } from "../agent/utils/tools";

const llm = new OpenAI({
model: "gpt-4o",
});

Settings.llm = llm;

async function singleWeatherAgent() {
const workflow = AgentWorkflow.fromTools({
tools: [getWeatherTool],
llm,
verbose: false,
});

Expand Down
2 changes: 1 addition & 1 deletion examples/node/workflow/basic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StartEvent, StopEvent, Workflow } from "@llamaindex/workflow";
import { StartEvent, StopEvent, Workflow } from "llamaindex";

type ContextData = {
counter: number;
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/app-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
} from "llamaindex";

const MAX_REVIEWS = 3;

Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
} from "llamaindex";

// Create LLM instance
const llm = new OpenAI();
Expand Down
7 changes: 1 addition & 6 deletions examples/workflow/joke.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { OpenAI } from "@llamaindex/openai";
import {
StartEvent,
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";

// Create LLM instance
const llm = new OpenAI();
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/stream-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
} from "llamaindex";

// Create LLM instance
const llm = new OpenAI();
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StartEvent, StopEvent, Workflow } from "@llamaindex/workflow";
import { StartEvent, StopEvent, Workflow } from "llamaindex";

const longRunning = async (_: unknown, ev: StartEvent<string>) => {
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for 2 seconds
Expand Down
7 changes: 1 addition & 6 deletions examples/workflow/validation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { OpenAI } from "@llamaindex/openai";
import {
StartEvent,
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";

// Create LLM instance
const llm = new OpenAI();
Expand Down
1 change: 1 addition & 0 deletions packages/llamaindex/src/index.edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export * from "@llamaindex/core/storage/index-store";
export * from "@llamaindex/core/storage/kv-store";
export * from "@llamaindex/core/utils";
export * from "@llamaindex/openai";
export * from "@llamaindex/workflow";
export * from "@llamaindex/workflow/agent";
export * from "./agent/index.js";
export * from "./cloud/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/workflow/src/agent/agent-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class AgentWorkflow {
timeout,
}: {
tools: BaseToolWithCall[];
llm: ToolCallLLM;
llm?: ToolCallLLM;
systemPrompt?: string;
verbose?: boolean;
timeout?: number;
Expand Down
5 changes: 3 additions & 2 deletions packages/workflow/src/agent/function-agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JSONObject } from "@llamaindex/core/global";
import { Settings } from "@llamaindex/core/global";
import type {
BaseToolWithCall,
ChatMessage,
Expand All @@ -23,7 +24,7 @@ export type FunctionAgentParams = {
/**
* LLM to use for the agent, required.
*/
llm: ToolCallLLM;
llm?: ToolCallLLM | undefined;
/**
* Description of the agent, useful for task assignment.
* Should provide the capabilities or responsibilities of the agent.
Expand Down Expand Up @@ -60,7 +61,7 @@ export class FunctionAgent implements BaseWorkflowAgent {
systemPrompt,
}: FunctionAgentParams) {
this.name = name;
this.llm = llm;
this.llm = llm ?? (Settings.llm as ToolCallLLM);
this.description = description;
this.tools = tools;
if (tools.length === 0) {
Expand Down
7 changes: 1 addition & 6 deletions unit/workflow/workflow-ui.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
StartEvent,
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";
import type { ReactNode } from "react";
import { describe, expect, test } from "vitest";

Expand Down
13 changes: 2 additions & 11 deletions unit/workflow/workflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import type {
HandlerContext,
StepHandler,
StepParameters,
} from "@llamaindex/workflow";
import {
StartEvent,
StopEvent,
Workflow,
WorkflowEvent,
} from "@llamaindex/workflow";
import type { HandlerContext, StepHandler, StepParameters } from "llamaindex";
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";
import {
beforeEach,
describe,
Expand Down

0 comments on commit c1b5be5

Please sign in to comment.