ailoy-node
    Preparing search index...

    Class Agent

    The Agent class provides a high-level interface for interacting with large language models (LLMs) in Ailoy. It abstracts the underlying runtime and VM logic, allowing users to easily send queries and receive streaming responses. Agents can be extended with external tools or APIs to provide real-time or domain-specific knowledge, enabling more powerful and context-aware interactions.

    Index

    Constructors

    • Parameters

      • runtime: Runtime

        The runtime environment associated with the agent

      • OptionalsystemMessage: string

        Optional system message to set the initial assistant context

      Returns Agent

    Methods

    • Adds a Javascript function as a tool using callable

      Parameters

      • f: (input: any) => any

        Function will be called when the tool invocation occured

      • desc: ToolDescription

        Tool descriotion

      Returns boolean

    • Adds a custom tool to the agent

      Parameters

      • tool: Tool

        Tool instance to be added

      Returns boolean

    • Create a MCP server and register its tools to agent.

      Parameters

      • name: string

        The unique name of the MCP server. If there's already a MCP server with the same name, it throws Error.

      • params: StdioServerParameters

        Parameters for connecting to the MCP stdio server

      • Optionaloptions: { toolsToAdd?: string[] }
        • OptionaltoolsToAdd?: string[]

          Optional list of tool names to add. If not specified, all tools are added.

      Returns Promise<void>

    • Loads tools from a predefined JSON preset file

      Parameters

      • presetName: string

        Name of the tool preset

      • Optionalargs: { authenticator?: ToolAuthenticator }
        • Optionalauthenticator?: ToolAuthenticator

          Optional authenticator to inject into the request

      Returns boolean

    • Clear the history of conversation messages.

      Returns void

    • Defines the LLM components to the runtime. This must be called before using any other method in the class. If already defined, this is a no-op.

      Parameters

      • modelName: ModelName

        The name of the LLM model to use in this instance

      • attrs: Record<string, any>

        `Additional input used as an attribute in the define call of Runtime

      Returns Promise<void>

    • Delete resources from the runtime. This should be called when the VectorStore is no longer needed. If already deleted, this is a no-op.

      Returns Promise<void>

    • Get the current conversation history. Each item in the list represents a message from either the user or the assistant.

      Returns Message[]

    • Parameters

      • message: string

        The user message to send to the model

      • Optionaloptions: { reasoning?: boolean }
        • Optionalreasoning?: boolean

          If True, enables reasoning capabilities (default: False)

      Returns AsyncGenerator<AgentResponse>

    • Removes the MCP server and its tools from the agent, with terminating the MCP server process.

      Parameters

      • name: string

        The unique name of the MCP server. If there's no MCP server matches the name, it throws Error.

      Returns Promise<void>