Key Interfaces
This page provides a reference for the core interfaces in the @ulifeai/agentb framework. Implementing or understanding these interfaces is crucial for extending AgentB or comprehending its internal workings.
IAgent
IAgentDefines the contract for an executable agent.
Import:
import { IAgent, IAgentContext, AgentEvent, LLMMessage } from '@ulifeai/agentb';Interface:
interface IAgent {
run(
agentContext: IAgentContext,
initialTurnMessages: LLMMessage[]
): AsyncGenerator<AgentEvent, void, undefined>;
submitToolOutputs?(
agentContext: IAgentContext,
toolCallOutputs: Array<{ tool_call_id: string; output: string; tool_name?: string }>
): AsyncGenerator<AgentEvent, void, undefined>;
cancelRun?(agentContext: IAgentContext): Promise<void>;
}run(agentContext, initialTurnMessages):The main execution method for the agent.
agentContext: IAgentContext: Provides all dependencies and configuration for the run.initialTurnMessages: LLMMessage[]: Messages that initiate this turn (e.g., new user input, or tool results from a previousrequires_actionstate).Returns:
AsyncGenerator<AgentEvent, void, undefined>- YieldsAgentEvents detailing the agent's progress.
submitToolOutputs?(agentContext, toolCallOutputs)(Optional):Handles submission of tool outputs if the agent paused in a
requires_actionstate.toolCallOutputs: Array of objects containingtool_call_id,output(string), and optionaltool_name.Returns:
AsyncGenerator<AgentEvent, void, undefined>- Yields furtherAgentEvents as the run continues.
cancelRun?(agentContext)(Optional):Initiates a cooperative cancellation of the current agent run.
Returns:
Promise<void>- Resolves when cancellation is acknowledged/processed.
Implementations: BaseAgent, PlanningAgent.
ITool
IToolDefines the contract for a tool that an agent can use.
Import:
Interface:
getDefinition():Returns (or a Promise of) an
IToolDefinitionobject, which describes the tool's name, purpose, and parameters to the LLM.
execute(input, agentContext?):Contains the tool's actual logic.
input: Input: Arguments for the tool, provided by the LLM based on the tool's definition.agentContext?: IAgentContext(Optional): Access to the agent's runtime context.Returns:
Promise<IToolResult<OutputData>>- The outcome of the tool's execution.IToolResult:{ success: boolean; data: OutputData; error?: string; metadata?: Record<string, any> }
Related: IToolDefinition, IToolParameter, IToolResult.
IToolProvider
IToolProviderDefines the contract for a component that supplies tools to an agent.
Import:
Interface:
getTools():Returns:
Promise<ITool[]>- All tools provided by this instance.
getTool(toolName):Returns:
Promise<ITool | undefined>- A specific tool by name.
ensureInitialized?()(Optional):Ensures the provider is ready (e.g.,
OpenAPIConnectorloads its spec).
Implementations: OpenAPIConnector, AggregatedToolProvider, custom providers.
IToolSet
IToolSetRepresents a named collection or logical group of tools.
Import:
Interface:
Used by ToolsetOrchestrator and DelegateToSpecialistTool.
ILLMClient
ILLMClientAbstracts interactions with a Large Language Model.
Import:
Interface:
generateResponse(messages, options): Core method to get LLM output (streaming or complete).countTokens(messages, model): Estimates token count.formatToolsForProvider?(toolDefinitions): Converts genericIToolDefinitions to the LLM provider's specific format.
Implementations: OpenAIAdapter.Related: LLMMessage, LLMMessageChunk, LLMToolCall, LLMToolChoice.
IThread
IThreadRepresents a conversation thread.
Import:
Interface:
IMessage
IMessageRepresents a single message within a thread.
Import:
Interface:
Storage Interfaces
These define contracts for data persistence.
Import:
IThreadStorage:createThread(data?): Promise<IThread>getThread(threadId): Promise<IThread | null>updateThread(threadId, updates): Promise<IThread>deleteThread(threadId): Promise<void>listThreads(filters?, pagination?): Promise<IThread[]>
IMessageStorage:addMessage(data): Promise<IMessage>getMessages(threadId, options?): Promise<IMessage[]>(IMessageQueryOptions)updateMessage(messageId, updates): Promise<IMessage>deleteMessage(messageId): Promise<void>
IAgentRunStorage:createRun(data): Promise<IAgentRun>getRun(runId): Promise<IAgentRun | null>updateRun(runId, updates): Promise<IAgentRun>
Implementations: MemoryStorage (default), conceptual stubs for SqlStorage, MongoDbStorage.Related: IAgentRun, IMessageQueryOptions.
This reference provides a quick lookup for the primary interfaces used throughout the AgentB framework. For more details on their usage and related types, refer to the specific component guides or the full source code.
Last updated