@just-every/task
Version:
Task - Thoughtful Task Loop
119 lines • 4.33 kB
TypeScript
/**
* Task Engine - Simplified Version
*
* Task implementation for LLM orchestration.
* Provides meta-cognition and thought delays on top of ensemble.
* Model rotation is handled by ensemble automatically.
*/
import type { TaskLocalState } from '../types/task-state.js';
import type { TaskStartEvent, TaskCompleteEvent, TaskFatalErrorEvent, TaskEvent, MetaMemoryEvent, MetaCognitionEvent, TaskStatusEvent } from '../types/events.js';
import { type ToolFunction, type Agent, type ResponseInput, type ProviderStreamEvent } from '@just-every/ensemble';
/**
* Get Task control tools
*/
export declare function getTaskTools(): ToolFunction[];
/**
* Resume a task from a previous state
*
* @param agent - The agent to use
* @param finalState - The final state from a previous task
* @param newContent - Optional new content to add to the conversation
* @returns AsyncGenerator that yields events
*
* @example
* ```typescript
* // First task
* let finalState;
* for await (const event of runTask(agent, 'Start analysis')) {
* if (event.type === 'task_complete') {
* finalState = event.finalState;
* }
* }
*
* // Resume with additional instructions
* for await (const event of resumeTask(agent, finalState, 'Continue with security analysis')) {
* // ...
* }
* ```
*/
export declare function resumeTask(agent: Agent, finalState: TaskEvent['finalState'], newContent?: string): AsyncGenerator<ProviderStreamEvent | TaskStartEvent | TaskCompleteEvent | TaskFatalErrorEvent | MetaMemoryEvent | MetaCognitionEvent>;
/**
* Run Mind with automatic everything
*
* @param agent - The agent from ensemble
* @param content - The task/prompt to execute
* @param initialState - Optional initial state for the task
* @returns AsyncGenerator that yields all ProviderStreamEvents and TaskEvents
*
* @example
* ```typescript
* import { Agent } from '@just-every/ensemble';
* import { runTask } from '@just-every/task';
*
* const agent = new Agent({
* name: 'MyAgent',
* modelClass: 'reasoning'
* });
*
* for await (const event of runTask(agent, 'Analyze this code')) {
* console.log(event);
* }
*
* // With initial state
* const state = { metaFrequency: '10', thoughtDelay: '2' };
* for await (const event of runTask(agent, 'Complex task', state)) {
* console.log(event);
* }
*
* // Handle task completion with state
* for await (const event of runTask(agent, 'Task')) {
* if (event.type === 'task_complete') {
* console.log('Result:', event.result);
* console.log('Final state:', event.finalState);
* }
* }
* ```
*/
export declare function runTask(agent: Agent, content: string, taskLocalState?: TaskLocalState): AsyncGenerator<ProviderStreamEvent | TaskStartEvent | TaskCompleteEvent | TaskFatalErrorEvent | MetaMemoryEvent | MetaCognitionEvent>;
/**
* Internal function to add a message to a messages array
* Used by both addMessageToTask and metacognition's inject_thought
*/
export declare function internalAddMessage(messages: ResponseInput, message: ResponseInput[0], source?: 'external' | 'metacognition'): void;
/**
* Add a message to an active task's message stream
*
* @param taskGenerator - The generator returned by runTask
* @param message - The message to inject
*
* @example
* ```typescript
* const task = runTask(agent, 'Analyze this code');
*
* // Inject a message while task is running
* addMessageToTask(task, {
* type: 'message',
* role: 'developer',
* content: 'Focus on performance issues'
* });
* ```
*/
export declare function addMessageToTask(taskGenerator: AsyncGenerator<ProviderStreamEvent>, message: ResponseInput[0]): void;
/**
* Get the current status of an active task
*
* @param taskGenerator - The generator returned by runTask
* @param agent - The agent to use for generating the summary
* @returns Promise<TaskStatusEvent> - The status of the task
*
* @example
* ```typescript
* const task = runTask(agent, 'Analyze this code');
*
* // Get status while task is running
* const status = await taskStatus(task, agent);
* console.log(status.data.summary);
* ```
*/
export declare function taskStatus(taskGenerator: AsyncGenerator<ProviderStreamEvent>, agent: Agent, prompt?: string): Promise<TaskStatusEvent>;
//# sourceMappingURL=engine.d.ts.map