@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
105 lines (104 loc) • 3.43 kB
TypeScript
/**
* Agent - Core agent implementation for NeuroLink
*
* An Agent wraps a NeuroLink instance with specialized behavior, instructions,
* and tool restrictions. Agents can be composed into networks for multi-agent
* orchestration using the agents-as-tools pattern.
*/
import type { z } from "zod";
import type { NeuroLink } from "../neurolink.js";
import type { AgentDefinition, AgentExecutionOptions, AgentInput, AgentInstance, AgentResult, AgentStatus, AgentStreamChunk } from "../types/index.js";
/**
* Agent - Wraps a NeuroLink instance with specialized behavior
*
* Features:
* - Custom instructions and persona
* - Tool restrictions per agent (via toolFilter on generate/stream)
* - Input/output schema validation
* - Streaming support
* - Execution metrics tracking
*
* @example
* ```typescript
* const agent = new Agent({
* id: 'researcher',
* name: 'Research Agent',
* description: 'Searches and analyzes information',
* instructions: 'You are a research assistant...',
* tools: ['websearchGrounding', 'readFile'],
* }, neurolink);
*
* const result = await agent.execute('Find information about quantum computing');
* ```
*/
export declare class Agent implements AgentInstance {
readonly id: string;
readonly name: string;
readonly description: string;
readonly instructions: string;
readonly provider?: string;
readonly model?: string;
readonly tools?: string[];
readonly inputSchema?: z.ZodSchema;
readonly outputSchema?: z.ZodSchema;
readonly maxSteps: number;
readonly temperature: number;
readonly canDelegate: boolean;
readonly metadata?: Record<string, unknown>;
private neurolink;
private emitter;
private executionCount;
private lastExecutionTime?;
private totalExecutionTime;
constructor(definition: AgentDefinition, neurolink: NeuroLink);
/**
* Execute the agent with given input
*
* @param input - Text input or structured data
* @param options - Execution options
* @returns Agent result with content and metadata
*/
execute(input: AgentInput, options?: AgentExecutionOptions): Promise<AgentResult>;
/**
* Stream execution results
*
* @param input - Text input or structured data
* @param options - Execution options
* @yields Agent stream chunks
*/
stream(input: AgentInput, options?: AgentExecutionOptions): AsyncIterable<AgentStreamChunk>;
/**
* Get agent status
*/
getStatus(): AgentStatus;
/**
* Get average execution time
*/
getAverageExecutionTime(): number;
/**
* Subscribe to agent events
*/
on(event: string, handler: (...args: unknown[]) => void): void;
/**
* Unsubscribe from agent events
*/
off(event: string, handler: (...args: unknown[]) => void): void;
/**
* Build prompt from input and context
*/
private buildPrompt;
/**
* Build generation options for NeuroLink.generate()
*
* Uses toolFilter to delegate tool restriction to BaseProvider.applyToolFiltering()
* rather than pre-filtering tools manually.
*/
private buildGenerateOptions;
/**
* Build stream options for NeuroLink.stream()
*
* Uses toolFilter to delegate tool restriction to BaseProvider.applyToolFiltering()
* rather than pre-filtering tools manually.
*/
private buildStreamOptions;
}