import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs'; import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs'; import { LightWitnessBase_V1 } from '@ibgib/core-gib/dist/witness/light-witness-base-v1.mjs'; import { IbGibSpaceAny } from '@ibgib/core-gib/dist/witness/space/space-base-v1.mjs'; import { MetaspaceService } from '@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs'; import { APIFunctionInfo } from '../../api/api-types.mjs'; import { FunctionInfoIbGib_V1 } from './function-info/function-info-one-file.mjs'; import { LiveProxyIbGib } from '../live-proxy-ibgib/live-proxy-ibgib-one-file.mjs'; import { AddTextsOpts, AgentWitnessData_V1, AgentWitnessIbGib_V1, AgentWitnessRel8ns_V1, PromptAPIResult, PromptInfo, PromptOneOffOpts, SetActiveContextOpts } from './agent-types.mjs'; /** * @extends LightWitnessBase_V1 * * ## notes * * This is far from complete. I don't know about performance, but it feels like * what we need to add: * * * initialization * * an agent should have a reference to the ibgib metaspace, as well as the agent's working local space. * * if no local space exists yet, one should be created. * * we will have to create an index ("special ibgib") that tracks our agents */ export declare abstract class AgentWitness_V1 extends LightWitnessBase_V1 implements AgentWitnessIbGib_V1 { protected lc: string; protected availableFunctions: Map; protected commentIbGibs_system: CommentIbGib_V1[]; protected commentIbGibs_chat: CommentIbGib_V1[]; protected _metaspace: MetaspaceService | undefined; /** * provider function for api key. */ fnGetAPIKey: () => Promise; /** * convenience getter for this.data.name */ get name(): string; /** * convenience getter for this.data.name */ get uuid(): string; protected _genAI: TAPIModel | undefined; /** * @protected * @property transientDecompressionPromptText - A temporary string that is * added to the prompt on the next LLM call ONLY, i.e. for a single prompt. * * This should NOT be part of any text history, but is rather a temporary * way of including text in a chat in a one-off manner. * * ## driving use case * * We're using this right now in relation with Function Call Requests from * this agent's model. We don't want to spam the context window with the * details of these function calls, but sometimes the model needs the * results of these functions. */ protected transientDecompressionPromptText: string | undefined; /** * @property fnOutputText - A property on the AgentWitness_V1 that provides a way to output text. * * Default implementation to do nothing. This is to avoid a null pointer. * ATOW (01/2025) This is a hack right now to get feedback from the agent that is not a function call. */ fnOutputText: (textResponse: string) => void; /** * we need this agent witness to basically update as a singleton. enforcing * singleton instances of agents is difficult even just locally, but * impossible when we consider that we may have multiple tabs/apps sharing * some space. * * So instead, we'll try having multiple witness instances wrapping the * proxy. */ protected ibGibProxy: LiveProxyIbGib | undefined; constructor(initialData?: AgentWitnessData_V1, initialRel8ns?: AgentWitnessRel8ns_V1); protected validateThis(): Promise; protected initialize(): Promise; /** * loads the new context (agent witness ibgib) if it's different than what * is already loaded in this agent instance. */ protected handleContextUpdated(): Promise; /** * each agent has access to its own local ibgib space for its internal contents. this gets the local * space that corresponds to the agent's spaceId, or if it does not already * exist, it creates the space (and updates the bootstrap). * @returns space object that the agent will use as its local space. * * todo: refactor this with options to possibly return other spaces as well (metaspace, subSpace, superSpace). if options is undefined, do existing behavior of getting only the subspace */ protected getSubSpace(): Promise; /** * helper that retrieves this agent's local space given by * this.data.superSpaceId */ protected getSuperSpace(): Promise; abstract addTexts(opts: AddTextsOpts): Promise; /** * quick and dirty, does not */ abstract promptOneOff(opts: PromptOneOffOpts): Promise; protected _activeContext: LiveProxyIbGib | undefined; /** * Updates the agent.data to have a soft link to an ibgib's timeline (via * its tjp addr) that defines the agent's current context. * * This is kinda like describing what "directory" the agent is "in", though * remember, ibgib's contain both intrinsic meaning (like a file) and * extrinsic meaning (like a folder/dir). * * @see {@link SetActiveContextOpts} */ setActiveContext(opts: SetActiveContextOpts): Promise; updateName({ name }: { name: string; }): Promise; updateAvailableFunctions({ availableFunctions, }: { availableFunctions: APIFunctionInfo[]; }): Promise; /** * I'm taking this out temporarily because it's non-trivial to figure out * where/when this should happen. We can just do the deprecated list and when * we go to populate the actual availble function infos, we check the * deprecated list and skip the ones that are deprecated. So in the agent's * dto ibgib (data.availableFunctions) the function name will still be * listed, but at runtime it will not be populated. */ /** * Performs the {@link mut8} transform on this agent and does extra * plumbing. */ protected mut8Self({ dataToAddOrPatch, }: { dataToAddOrPatch: Partial; }): Promise; /** * gets a list of api function infos available as tools to this agent, i.e., atow this are available for function calling in Gemini API. implementation is a WIP. * * @returns array of api function infos available as tools to this agent */ protected getAvailableFunctions(): readonly APIFunctionInfo[]; protected getComments_System(): readonly CommentIbGib_V1[]; protected getComments_Chat(): readonly CommentIbGib_V1[]; addAvailableFunctions(functionInfos: APIFunctionInfo[]): Promise; /** * Generates the prompt text for the LLM by concatenating system and chat * comments. This method is meant to be overridden by descendant classes if * needed. * * @returns A {@link TPromptInfo} object that will be used to prompt {@link _genAI} * @throws {Error} If there is an error parsing the addlMetadataText, or if no metaspace is set, or if there are no chat comment ibgibs. (why are we prompting?) */ abstract composePromptInfo(): Promise; /** * Calls the text-based API to get a response based on the given prompt. * This method is meant to be overridden by descendant classes if needed. * * @param {string} prompt - The text prompt to send to the API. * @returns {Promise} - The response from the API. * @throws {Error} If the api is not supported or if there is an error with the Gemini API call. */ protected abstract callTextAPI(info: PromptInfo): Promise; /** * Orchestrates the prompting of the agent, combining system and chat history, * and processing any function calling that is returned from the API. * This method is called via the witness function when it receives a ROOT input. * @returns {Promise} * @throws {Error} If there is an error getting the prompt text, calling the text API, or processing the response. */ doPrompt(): Promise; /** * handles text when there are no function calls * @param text string */ protected doPrompt_text(text: string): Promise; /** * @protected * Handles the prompt function calls when there are one or more calls * requested by the LLM. * * * parses, validates, executes those function calls * * creates associated function info ibgibs * * creates Function Call Request comment ibgib and relates this to this agent * * recursively calls doPrompt if indicated by the LLM (if they want to be * reprompted after the function calls) * * @param {string[]} functionCalls are raw stringified JSON fn calls requested by the LLM */ protected doPrompt_functionCalls({ functionCalls }: { functionCalls: string[]; }): Promise; protected doPrompt_functionCalls_createFunctionInfoIbGibsAndExecFunctionCalls({ functionCalls, }: { functionCalls: string[]; }): Promise; protected doPrompt_functionCalls_addFunctionCallRequestComment({ functionInfoIbGibs }: { functionInfoIbGibs: FunctionInfoIbGib_V1[]; }): Promise; protected doPrompt_functionCalls_getTransientDecompressionPromptForNextPrompt({ functionInfoIbGibs }: { functionInfoIbGibs: FunctionInfoIbGib_V1[]; }): Promise; /** * naive counter for reprompt asked for by the model */ repromptCount: number; /** * naive cap for reprompt asked for by the model */ repromptMax: number; /** * recursively calls doPrompt depending on {@link repromptCount} and {@link repromptMax} */ rePrompt(): Promise; witness(arg: IbGib_V1): Promise; } export type AgentWitnessAny = AgentWitness_V1; //# sourceMappingURL=agent-one-file.d.mts.map