Skip to content

Commit a6ad4fa

Browse files
committed
Implement WorkflowDrivenAgent documentation and remove outdated examples
- Added detailed documentation for the new `WorkflowDrivenAgent`, explaining its features, usage, and integration with existing systems. - Included a code example demonstrating the creation and execution of a workflow using the `WorkflowDrivenAgent`. - Removed outdated example files and tests related to the `WorkflowDrivenAgent` to streamline the codebase and improve clarity.
1 parent 4a0e74f commit a6ad4fa

File tree

12 files changed

+148
-1371
lines changed

12 files changed

+148
-1371
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,67 @@ For more details on how to utilize observability features in KaibanJS, please vi
517517

518518
</details>
519519

520+
<details style="margin-bottom:10px;">
521+
<summary><b style="color:black;">WorkflowDrivenAgent</b></summary>
522+
523+
<p style="margin-top:10px;">
524+
The `WorkflowDrivenAgent` is a specialized agent that executes workflows instead of using LLM-based reasoning. This agent maintains workflow state and can handle suspension and resumption operations for long-running workflows, providing a deterministic approach to task execution.
525+
526+
In this example, a `WorkflowDrivenAgent` is created to execute a workflow that processes data through defined steps, allowing for complex multi-step operations without LLM calls.
527+
528+
</p>
529+
530+
```js
531+
import { Agent } from 'kaibanjs';
532+
import { createStep, createWorkflow } from '@kaibanjs/workflow';
533+
import { z } from 'zod';
534+
535+
// Create workflow steps
536+
const processStep = createStep({
537+
id: 'process',
538+
inputSchema: z.object({ data: z.string() }),
539+
outputSchema: z.object({ result: z.string() }),
540+
execute: async ({ inputData }) => {
541+
const { data } = inputData as { data: string };
542+
return { result: data.toUpperCase() };
543+
},
544+
});
545+
546+
// Create the workflow
547+
const workflow = createWorkflow({
548+
id: 'example-workflow',
549+
inputSchema: z.object({ data: z.string() }),
550+
outputSchema: z.object({ result: z.string() }),
551+
});
552+
553+
workflow.then(processStep);
554+
workflow.commit();
555+
556+
// Create the agent using the Agent wrapper
557+
const agent = new Agent({
558+
type: 'WorkflowDrivenAgent',
559+
name: 'Workflow Agent',
560+
workflow: workflow,
561+
});
562+
563+
// Use the agent in a team
564+
const team = new Team({
565+
name: 'Workflow Team',
566+
agents: [agent],
567+
tasks: [
568+
new Task({
569+
description: 'Process the input data using workflow',
570+
expectedOutput: 'Processed data result',
571+
agent: agent,
572+
}),
573+
],
574+
});
575+
```
576+
577+
_The `WorkflowDrivenAgent` integrates seamlessly with the existing team system, supports workflows with suspension for manual intervention, and provides detailed logging for workflow events. For more information, visit the [WorkflowDrivenAgent documentation](https://github.com/kaiban-ai/KaibanJS/tree/main/packages/workflow/src/examples/kaibanjs-integration-readme.md)._
578+
579+
</details>
580+
520581
## Documentation
521582

522583
- [Official Documentation](https://docs.kaibanjs.com/category/get-started)

packages/workflow/src/examples/README.md renamed to packages/workflow/src/examples/kaibanjs-integration-readme.md

File renamed without changes.

playground/react/NEW_EXAMPLE_README.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

playground/react/README.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,90 @@
1-
# React + Vite
1+
# KaibanJS React Playground
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
This playground demonstrates various KaibanJS features including workflow-driven agents, LLM integrations, and team collaboration patterns.
44

5-
Currently, two official plugins are available:
5+
## Features
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
- **Workflow-Driven Agents**: Demonstrates structured workflow execution
8+
- **Multi-SDK Integration**: Combines LangChain and Vercel AI SDK
9+
- **Team Collaboration**: Shows how different agent types work together
10+
- **Storybook Integration**: Interactive examples and documentation
11+
12+
## Environment Variables
13+
14+
Create a `.env` file in the root directory with the following variables:
15+
16+
```bash
17+
# OpenAI API Key for LangChain and AI SDK
18+
VITE_OPENAI_API_KEY=your_openai_api_key_here
19+
20+
# Anthropic API Key for ReactChampionAgent
21+
VITE_ANTHROPIC_API_KEY=your_anthropic_api_key_here
22+
23+
# Tavily API Key for web search
24+
VITE_TAVILY_API_KEY=your_tavily_api_key_here
25+
```
26+
27+
## Getting Started
28+
29+
1. **Build the workflow package first** (required for local development):
30+
31+
```bash
32+
cd ../../packages/workflow
33+
npm install
34+
npm run build
35+
cd ../../playground/react
36+
```
37+
38+
> **Important**: The workflow package must be built before running the playground because it uses a local file reference (`file:../../packages/workflow`) in its dependencies. This ensures the latest workflow code is available to the playground.
39+
40+
2. Install dependencies:
41+
42+
```bash
43+
npm install
44+
```
45+
46+
3. Set up environment variables (see above)
47+
48+
4. Start the development server:
49+
50+
```bash
51+
npm run dev
52+
```
53+
54+
5. Start Storybook for interactive examples:
55+
```bash
56+
npm run storybook
57+
```
58+
59+
## Available Stories
60+
61+
- **Basic Workflow**: Simple mathematical workflow
62+
- **Complex Workflow**: Advanced patterns with conditional logic
63+
- **Suspension Workflow**: Workflow with pause/resume capabilities
64+
- **Mixed Team**: WorkflowDrivenAgent + ReactChampionAgent collaboration
65+
- **LangChain + AI SDK Workflow**: Multi-SDK integration example
66+
- **LangChain Only Workflow**: Pure LangChain implementation
67+
- **AI SDK Only Workflow**: Pure Vercel AI SDK implementation with web search tool
68+
69+
## Troubleshooting
70+
71+
### Common Issues
72+
73+
1. **"Module not found" errors**: Make sure you've built the workflow package first (step 1 above)
74+
75+
2. **"crypto.randomUUID is not a function"**: This is a browser compatibility issue. The workflow package includes a polyfill, but you may need to clear your browser cache or restart the dev server.
76+
77+
3. **API Key errors**: Ensure all required environment variables are set in your `.env` file
78+
79+
4. **Tool calling errors**: Make sure you have the latest version of the AI SDK packages installed
80+
81+
### Rebuilding After Changes
82+
83+
If you make changes to the workflow package, you'll need to rebuild it:
84+
85+
```bash
86+
cd ../../packages/workflow
87+
npm run build
88+
cd ../../playground/react
89+
# Restart your dev server or Storybook
90+
```

0 commit comments

Comments
 (0)