Skip to content

Commit

Permalink
refactor(types): update type definitions for Agent, Task, and Team cl… (
Browse files Browse the repository at this point in the history
#205)

…asses

- Refactored type definitions in `index.d.ts` and `types.d.ts`
- Added new methods and properties to Agent, Task, and Team classes
- Updated method signatures to use getters instead of method calls
- Introduced new interfaces like IWorkflowStats and ITeamWorkflowResult
- Enhanced type safety and added more comprehensive type definitions
  • Loading branch information
darielnoel authored Jan 29, 2025
2 parents 29f9c98 + d70bc04 commit 14b3b64
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 43 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ For more details on how to utilize observability features in KaibanJS, please vi
- [LLM-friendly Documentation](https://docs.kaibanjs.com/llms-full.txt) - Optimized for AI tools and coding assistants
- [Join Our Discord](https://www.kaibanjs.com/discord)


### Compatibility

KaibanJS aims to be compatible with major front-end frameworks like React, Vue, Angular, and NextJS, making it a versatile choice for developers. The JavaScript ecosystem is a "bit complex...". If you have any problems, please tell us and we'll help you fix them.
Expand Down
30 changes: 15 additions & 15 deletions packages/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ npm install @kaibanjs/tools

Here's a list of all available tools. Click on the tool names to view their detailed documentation.

| Tool | Description | Documentation |
| ---------------- | ---------------------------------------------------------------------- | --------------------------------------- |
| Exa | AI-focused search engine using embeddings to organize web data | [README](src/exa/README.md) |
| Firecrawl | Web scraping service for extracting structured data | [README](src/firecrawl/README.md) |
| GitHub Issues | GitHub API integration for fetching and analyzing repository issues | [README](src/github-issues/README.md) |
| Jina URL to MD | Convert web content into clean, LLM-ready markdown using Jina.ai | [README](src/jina-url-to-markdown/README.md) |
| PDF Search | Extract and search content from PDF documents | [README](src/pdf-search/README.md) |
| Serper | Google Search API integration with support for multiple search types | [README](src/serper/README.md) |
| Simple RAG | Basic Retrieval-Augmented Generation implementation for Q&A | [README](src/simple-rag/README.md) |
| Tavily Search | AI-optimized search engine for comprehensive and accurate results | [README](src/tavily/README.md) |
| Text File Search | Search and analyze content within text files | [README](src/textfile-search/README.md) |
| Website Search | Semantic search within website content using RAG models | [README](src/website-search/README.md) |
| WolframAlpha | Computational intelligence engine for complex queries and calculations | [README](src/wolfram-alpha/README.md) |
| Zapier Webhook | Integration with Zapier for workflow automation | [README](src/zapier-webhook/README.md) |
| Make Webhook | Integration with Make (formerly Integromat) for workflow automation | [README](src/make-webhook/README.md) |
| Tool | Description | Documentation |
| ---------------- | ---------------------------------------------------------------------- | -------------------------------------------- |
| Exa | AI-focused search engine using embeddings to organize web data | [README](src/exa/README.md) |
| Firecrawl | Web scraping service for extracting structured data | [README](src/firecrawl/README.md) |
| GitHub Issues | GitHub API integration for fetching and analyzing repository issues | [README](src/github-issues/README.md) |
| Jina URL to MD | Convert web content into clean, LLM-ready markdown using Jina.ai | [README](src/jina-url-to-markdown/README.md) |
| PDF Search | Extract and search content from PDF documents | [README](src/pdf-search/README.md) |
| Serper | Google Search API integration with support for multiple search types | [README](src/serper/README.md) |
| Simple RAG | Basic Retrieval-Augmented Generation implementation for Q&A | [README](src/simple-rag/README.md) |
| Tavily Search | AI-optimized search engine for comprehensive and accurate results | [README](src/tavily/README.md) |
| Text File Search | Search and analyze content within text files | [README](src/textfile-search/README.md) |
| Website Search | Semantic search within website content using RAG models | [README](src/website-search/README.md) |
| WolframAlpha | Computational intelligence engine for complex queries and calculations | [README](src/wolfram-alpha/README.md) |
| Zapier Webhook | Integration with Zapier for workflow automation | [README](src/zapier-webhook/README.md) |
| Make Webhook | Integration with Make (formerly Integromat) for workflow automation | [README](src/make-webhook/README.md) |

## Development

Expand Down
32 changes: 25 additions & 7 deletions playground/nodejs-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 94 additions & 20 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
// Definitions by: @alienkarma <github.com/alienkarma>

import { Tool } from 'langchain/tools';
import type { AGENT_STATUS_enum, TASK_STATUS_enum } from './enums.d.ts';
import type {
AGENT_STATUS_enum,
TASK_STATUS_enum,
WORKFLOW_STATUS_enum,
} from './enums.d.ts';
import type {
BaseAgent,
IBaseAgentParams,
ILLMConfig,
ITaskStats,
TAgentTypes,
TStore,
ILLMUsageStats,
} from './types.d.ts';

/**
Expand Down Expand Up @@ -79,61 +84,92 @@ export class Agent {
* Returns the agent ID.
* @returns {string} The agent ID.
*/
id(): string;
get id(): string;

/**
* Returns the agent name.
* @returns {string} The agent name.
*/
name(): string;
get name(): string;

/**
* Returns the agent role.
* @returns {string} The agent role.
*/
role(): string;
get role(): string;

/**
* Returns the agent goal.
* @returns {string} The agent goal.
*/
goal(): string;
get goal(): string;

/**
* Returns the agent background.
* @returns {string} The agent background.
*/
background(): string;
get background(): string;

/**
* Returns the tools available to the agent.
* @returns {Tool[]} The list of tools.
*/
tools(): Tool[];
get tools(): Tool[];

/**
* Returns the status of the agent.
* @returns {AGENT_STATUS_enum} The agent's status.
*/
status(): AGENT_STATUS_enum;
get status(): AGENT_STATUS_enum;

/**
* Returns the configuration for the language model.
* @returns {ILLMConfig} The language model configuration.
*/
llmConfig(): ILLMConfig;
get llmConfig(): ILLMConfig;

/**
* Returns the system message for the language model.
* @returns {string} The language model system message.
*/
llmSystemMessage(): string;
get llmSystemMessage(): string;

/**
* Indicates whether the agent is forced to provide a final answer.
* @returns {boolean} True if the agent is forced to give a final answer, otherwise false.
*/
forceFinalAnswer(): boolean;
get forceFinalAnswer(): boolean;

/**
* Returns the prompt templates for the agent.
* @returns {Record<string, string>} The prompt templates.
*/
get promptTemplates(): Record<string, string>;

/**
* Works on a task.
* @param {Task} task - The task to work on.
* @param {any} inputs - The inputs for the task.
* @param {any} context - The context for the task.
* @returns {Promise<any>} A promise resolving with the result of the task.
*/
workOnTask(task: Task, inputs: any, context: any): Promise<any>;

/**
* Works on feedback.
* @param {Task} task - The task to work on.
* @param {any} inputs - The inputs for the task.
* @param {any} context - The context for the task.
* @returns {Promise<any>} A promise resolving with the result of the task.
*/
workOnFeedback(task: Task, inputs: any, context: any): Promise<any>;

/**
* Initializes the agent.
* @param {TStore} store - The store to initialize.
* @param {Record<string, any>} env - The environment variables to initialize.
*/
initialize(store: TStore, env: Record<string, any>): void;
}

/**
Expand All @@ -144,15 +180,17 @@ export class Agent {
* @property {string} expectedOutput - The expected output of the task.
* @property {BaseAgent} agent - The agent to execute the task.
* @property {boolean} [isDeliverable] - Indicates whether the task is deliverable.
* @property {object} [outputSchema] - The schema for validating the task output.
* @property {boolean} [externalValidationRequired] - Indicates whether external validation is required.
* @property {object | null} [outputSchema] - The schema for validating the task output.
*/
export interface ITaskParams {
title?: string;
description: string;
expectedOutput: string;
agent: Agent;
isDeliverable?: boolean;
outputSchema?: object;
externalValidationRequired?: boolean;
outputSchema?: object | null;
}

/**
Expand All @@ -166,13 +204,14 @@ export interface ITaskParams {
* @property {boolean} isDeliverable - Indicates whether the task is deliverable.
* @property {Agent} agent - The agent to execute the task.
* @property {TASK_STATUS_enum} status - The status of the task.
* @property {string} result - The result of the task.
* @property {string | null} result - The result of the task.
* @property {ITaskStats | null} stats - The statistics of the task.
* @property {number | null} duration - The duration of the task.
* @property {Task[]} dependencies - The dependencies of the task.
* @property {string | null} interpolatedTaskDescription - The interpolated task description.
* @property {TStore} store - The store.
* @property {boolean} externalValidationRequired - Indicates whether external validation is required.
* @property {object | null} outputSchema - The schema for validating the task output.
* @property {TStore | undefined} store - The store.
*/
export class Task {
id: string;
Expand All @@ -182,13 +221,15 @@ export class Task {
isDeliverable: boolean;
agent: Agent;
status: TASK_STATUS_enum;
result: string;
result: string | null;
stats: ITaskStats | null;
duration: number | null;
dependencies: Task[];
interpolatedTaskDescription: string | null;
store: TStore;
feedbackHistory: any[];
externalValidationRequired: boolean;
outputSchema: object | null;
store?: TStore;

/**
* Creates an instance of a Task.
Expand All @@ -215,8 +256,8 @@ export class Task {
*/
export interface ITeamParams {
name: string;
agents?: Agent[];
tasks?: Task[];
agents: Agent[];
tasks: Task[];
logLevel?: string;
inputs?: Record<string, any>;
env?: Record<string, any> | null;
Expand All @@ -241,7 +282,7 @@ export class Team {
* Starts the team operations.
* @returns {Promise<void>} A promise resolving when the team has started.
*/
start(): Promise<void>;
start(inputs?: Record<string, any> | null): Promise<ITeamWorkflowResult>;

/**
* Returns the store.
Expand All @@ -265,4 +306,37 @@ export class Team {
listener: (newValues: any) => void,
properties?: string[]
): () => void;

provideFeedback(taskId: string, feedbackContent: string): void;
validateTask(taskId: string): void;
onWorkflowStatusChange(
callback: (status: WORKFLOW_STATUS_enum) => void
): () => void;
getTasksByStatus(status: TASK_STATUS_enum): Task[];
getWorkflowStatus(): WORKFLOW_STATUS_enum;
getWorkflowResult(): any | null;
getTasks(): Task[];
getWorkflowStats(): IWorkflowStats | null;
}

export interface ITeamWorkflowResult {
status: WORKFLOW_STATUS_enum;
result: any;
stats: IWorkflowStats | null;
}

export interface IWorkflowStats {
startTime: number;
endTime: number;
duration: number;
llmUsageStats: ILLMUsageStats;
iterationCount: number;
costDetails: {
costInputTokens: number;
costOutputTokens: number;
totalCost: number;
};
teamName: string;
taskCount: number;
agentCount: number;
}
10 changes: 10 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export declare class BaseAgent {
maxIterations: number;
forceFinalAnswer: boolean;
llmInstance: any;
promptTemplates: IPromptTemplates;

/**
* Creates an instance of BaseAgent.
Expand All @@ -96,6 +97,10 @@ export declare class BaseAgent {
* @param {Record<string, any>} env - The environment variables to be set.
*/
setEnv(env: Record<string, any>): void;

workOnTask(task: Task, inputs: any, context: any): Promise<any>;
workOnFeedback(task: Task, inputs: any, context: any): Promise<any>;
initialize(store: TStore, env: Record<string, any>): void;
}

/**
Expand Down Expand Up @@ -161,3 +166,8 @@ export interface ITaskStats {
llmUsageStats: ILLMUsageStats;
iterationCount: number;
}

// Add missing prompt templates interface
export interface IPromptTemplates {
[key: string]: string;
}

0 comments on commit 14b3b64

Please sign in to comment.