arcananex-synapse
Version:
Agentic AI framework
115 lines (114 loc) • 4.1 kB
TypeScript
import { ChainCommand, Command } from "./command";
import { LLMInvoker, UserMessage, Memory } from "./llm-invoker";
export interface AgentTask {
agent: string;
command: string;
originalInput: UserMessage[];
[key: string]: any;
}
export interface AgentConfig {
defaultMemory: Memory[];
[key: string]: any;
}
/**
* Example usage:
*
* This code might typically be placed in an application bootstrap file.
*
* @example
* ```typescript
* async function main() {
* // Configuration options - these can be loaded from environment variables or a config file.
* const config: AgentConfig = {
* defaultMemory: [<AI system memory>]
* };
*
* const agent = new Agent(config);
*
* // Create and register an Email command.
* const emailCommand = new Command<AgentTask, void>();
* emailCommand.setTask(async (task: AgentTask) => {
* console.log(
* `[EmailCommand] Processing email command: "${task.command}"`
* );
*
* // Implement email logic here (e.g., trigger an email sending service).
* });
*
* agent.registerAgent("email", emailCommand);
*
* // Always running agent
* agent.registerAlwaysRunAgent("analytic", analyticCommand);
*
* // Optionally, you can register other commands here by creating new Command instances
* // and assigning them tasks that match your application's behavior.
*
* // Process an input prompt. The LLM is expected to choose an appropriate agent.
* const testInput = "Initiate onboarding email sequence for new users";
* await agent.processInput(testInput);
* }
* ```
------------------------------
Agent class.
This class encapsulates communication with AWS Bedrock,
synthesizes the LLM response into an AgentTask,
and dispatches the task to the appropriate command from a registry.
------------------------------
*/
export declare class Agent {
private llmInvoker;
private registry;
private alwaysRunAgents;
private defaultCommand;
private defaultMemory;
/**
* @param llmInvoker An instance that conforms to the LLMInvoker interface.
* @param config Optional configuration.
*/
constructor(llmInvoker: LLMInvoker, config: AgentConfig);
/**
* Registers a new command (agent) to handle tasks.
*
* @param agentName Unique key identifying the command.
* @param command A Command instance that encapsulates the behavior.
*/
registerAgent(agentName: string, command: Command<AgentTask, any> | ChainCommand<AgentTask | unknown, any>): void;
/**
* Register an always-run (parallel) agent that executes on every input.
* @param agentName Unique identifier (for logging) and the command instance.
* @param command A Command instance to run regardless of LLM routing.
*/
registerAlwaysRunAgent(agentName: string, command: Command<AgentTask, any> | ChainCommand<AgentTask | unknown, any>): void;
/**
* Dispatches an AgentTask to the appropriate command.
* Returns the output of the executed command.
*
* @param task The task generated from the LLM response.
*/
dispatchTask(task: AgentTask): Promise<any>;
/**
* Processes a user input prompt:
* • Converts it into a UserMessage.
* • Calls the injected LLM client.
* • Decodes the response to synthesize an AgentTask.
* • Dispatches the task and returns its output.
*
* @param input The user input string.
* @param memories Optionally, a list of Memory objects.
*/
processInput(input: UserMessage[], memories?: Memory[]): Promise<any>;
/**
* Returns the registry of commands.
* Each command is represented by its name and the command instance.
*/
getRegistry(): Map<string, Command<AgentTask, any> | ChainCommand<AgentTask | unknown, any>>;
/**
* Returns the list of always-run agents.
* Each agent is represented by its name and the command to execute.
*/
getAlwaysRunAgents(): Array<{
agentName: string;
command: Command<AgentTask, any> | ChainCommand<AgentTask | unknown, any>;
}>;
}
//# sourceMappingURL=agent.d.ts.map