# Class Agent

The core Agent class for creating and managing AI agents.

An Agent combines models, skills, and behaviors to create intelligent assistants that can process prompts, maintain conversations, and execute tasks.

#### Example

    // Create a simple agent
    const agent = new Agent({
      name: "Assistant",
      model: "gpt-4",
      behavior: "You are a helpful assistant."
    });

    // Use the agent
    const response = await agent.prompt("Hello, how can you help me?");
    console.log(response);

    // Add skills to the agent
    agent.addSkill({
      name: "calculator",
      description: "Perform mathematical calculations",
      process: (a, b) => a + b
    });

#### Hierarchy (View Summary)

- SDKObject
  - Agent

- Defined in src/Agent/Agent.class.ts:290

##### Index

### Constructors

constructor

### Properties

_readyPromise

### Accessors

behavior
cache
data
hasExplicitId
id
llm
modes
ready
scheduler
skillNames
storage
structure
team
vault
vectorDB

### Methods

addSkill
call
chat
emit
init
initSignal
mcp
off
on
once
prompt
removeListener
removeSkill
setMode
sync
unsetMode
import

## Constructors

### constructor

- new Agent(_settings: TAgentSettings): Agent

  Create a new Agent instance.

  #### Parameters

  - _settings: TAgentSettings

    Configuration object for the agent

  #### Returns Agent

  #### Example

      const agent = new Agent({
        name: "Data Analyst",
        model: "gpt-4",
        behavior: "You are an expert data analyst who provides insights."
      });

  Overrides SDKObject.constructor

  - Defined in src/Agent/Agent.class.ts:395

## Properties

### `Protected`_readyPromise

_readyPromise: ControlledPromise<any>

Inherited from SDKObject._readyPromise

- Defined in src/Core/SDKObject.class.ts:17

## Accessors

### behavior

- get behavior(): string

  #### Returns string

  - Defined in src/Agent/Agent.class.ts:320
- set behavior(behavior: string): void

  #### Parameters

  - behavior: string

  #### Returns void

  - Defined in src/Agent/Agent.class.ts:324

### cache

- get cache(): TCacheProviderInstances

  #### Returns TCacheProviderInstances

  - Defined in src/Agent/Agent.class.ts:637

### data

- get data(): AgentData

  The agent data : this is the equivalent of the .smyth file content.

  Used for by external operations to get the agent data

  #### Returns AgentData

  - Defined in src/Agent/Agent.class.ts:362

### hasExplicitId

- get hasExplicitId(): boolean

  #### Returns boolean

  - Defined in src/Agent/Agent.class.ts:292

### id

- get id(): string

  #### Returns string

  - Defined in src/Agent/Agent.class.ts:316

### llm

- get llm(): TLLMProviderInstances

  Access to LLM instances for direct model interactions.

  Supported providers and calling patterns:

  - `agent.llm.openai(modelId, params)` - OpenAI models
  - `agent.llm.anthropic(modelId, params)` - Anthropic models

  #### Returns TLLMProviderInstances

  #### Example

      // Direct model access
      const gpt4 = agent.llm.openai('gpt-4', { temperature: 0.7 });
      const response = await gpt4.prompt("Explain quantum computing");

      // Using configuration object
      const claude = agent.llm.anthropic({
        model: 'claude-3-sonnet',
        maxTokens: 1000
      });

      // Streaming response
      const stream = await claude.prompt("Write a poem").stream();
      stream.on('data', chunk => console.log(chunk));

  - Defined in src/Agent/Agent.class.ts:565

### modes

- get modes(): TAgentMode[]

  #### Returns TAgentMode[]

  - Defined in src/Agent/Agent.class.ts:328

### ready

- get ready(): ControlledPromise<any>

  #### Returns ControlledPromise<any>

  Inherited from SDKObject.ready

  - Defined in src/Core/SDKObject.class.ts:19

### scheduler

- get scheduler(): TSchedulerProviderInstances

  #### Returns TSchedulerProviderInstances

  - Defined in src/Agent/Agent.class.ts:720

### skillNames

- get skillNames(): any[]

  #### Returns any[]

  - Defined in src/Agent/Agent.class.ts:822

### storage

- get storage(): TStorageProviderInstances

  #### Returns TStorageProviderInstances

  - Defined in src/Agent/Agent.class.ts:611

### structure

- get structure(): any

  The agent internal structure used for by internal operations to generate the agent data

  #### Returns any

  - Defined in src/Agent/Agent.class.ts:340
- set structure(structure: any): void

  #### Parameters

  - structure: any

  #### Returns void

  - Defined in src/Agent/Agent.class.ts:343

### team

- get team(): Team

  #### Returns Team

  - Defined in src/Agent/Agent.class.ts:350

### vault

- get vault(): VaultInstance

  Access to the agent's team vault

  This will give you access to the current agent team vault, if no explicit team is set, the agent belongs to "default" team.

  #### Returns VaultInstance

  The vault instance

  #### Example

      const value = await agent.vault.get('my-key');

  - Defined in src/Agent/Agent.class.ts:757

### vectorDB

- get vectorDB(): TVectorDBProviderInstances

  #### Returns TVectorDBProviderInstances

  - Defined in src/Agent/Agent.class.ts:672

## Methods

### addSkill

- addSkill(
  settings?: TSkillSettings,
  ): {
  in: (inputs: TSkillInputs) => void;
  out: { body: any; headers: any; query: any; [key: string]: any };
  }

  Add a skill to the agent, enabling it to perform specific tasks or operations.

  Skills extend the agent's capabilities by providing custom functions that can be called during conversations or prompt processing.

  A skill can be implemented in two ways:

  1. With a process function that defines the skill's core logic
  2. As a workflow entry point that can be connected to other components to build complex logic

  #### Parameters

  - `Optional` settings: TSkillSettings

  #### Returns {
  in: (inputs: TSkillInputs) => void;
  out: { body: any; headers: any; query: any; [key: string]: any };
  }

  #### Example

      // Add a data fetching skill
      agent.addSkill({
        name: "fetch_weather",
        description: "Get current weather for a location",
        process: async (location) => {
          const response = await fetch(`/api/weather?location=${location}`);
          return response.json();
        }
      });

      // Add a skill that will be used as an entry point in a workflow
      agent.addSkill({
        name: "fetch_weather",
        description: "Get current weather for a location",
      });

      // Attach the skill to a workflow

  - Defined in src/Agent/Agent.class.ts:797

### call

- call(skillName: string, ...args: any[]): Promise<{}>

  #### Parameters

  - skillName: string
  - ...args: any[]

  #### Returns Promise<{}>

  - Defined in src/Agent/Agent.class.ts:826

### chat

- chat(options?: string | ChatOptions): Chat

  Create a new chat session with the agent.

  Chat sessions maintain conversation context and allow for back-and-forth interactions with the agent, preserving message history.

  #### Parameters

  - `Optional` options: string | ChatOptions

    The options for the chat session if you provide a string it'll be used as the chat ID and persistence will be enabled by default

    - string
    - ChatOptions

      - ##### `Optional` baseUrl?: string

        The base URL to use for tool calls this is useful if you are trying to call tools from a remote agent

      - ##### `Optional` id?: string

        The ID of the chat. If not provided, a random ID will be generated.

        If provided, it will be used to identify the chat in the storage provider and try to load the previous messages from the storage provider if the chat is not found, a new chat will be created

      - ##### `Optional` maxContextSize?: number

        The maximum number of tokens to use for the context window

      - ##### `Optional` maxOutputTokens?: number

        The maximum number of tokens to use for the output

      - ##### `Optional` model?: string | TLLMModel

        The model to use for the chat

      - ##### `Optional` persist?: boolean | ILLMContextStore

        If true, the chat will be persisted in the default SRE storage provider : next time you create a chat with the same chat ID and same agent ID, it will load the previous messages from the storage provider

        If false, the chat will not be persisted

        If a ILLMContextStore is provided, the chat will be persisted in the provided store

  #### Returns Chat

  Chat instance for interactive conversations

  #### Example

      const chat = agent.chat();

      // Send messages in sequence
      await chat.send("Hello, I need help with my project");
      await chat.send("Can you explain the benefits?");
      await chat.send("What are the next steps?");

      // Get conversation history
      const history = chat.getHistory();

  - Defined in src/Agent/Agent.class.ts:934

### emit

- emit(event: string, ...args: any[]): void

  #### Parameters

  - event: string
  - ...args: any[]

  #### Returns void

  Inherited from SDKObject.emit

  - Defined in src/Core/SDKObject.class.ts:45

### `Protected` init

- init(): Promise<void>

  #### Returns Promise<void>

  Overrides SDKObject.init

  - Defined in src/Agent/Agent.class.ts:442

### `Protected` initSignal

- initSignal(): Promise<void>

  #### Returns Promise<void>

  Inherited from SDKObject.initSignal

  - Defined in src/Core/SDKObject.class.ts:37

### mcp

- mcp(transport: MCPTransport, port?: number): Promise<string>

  Expose the agent as a MCP (Model Context Protocol) server

  The MCP server can be started in two ways:

  - STDIO: The MCP server will be started in STDIO mode
  - SSE: The MCP server will be started in SSE mode, this is case the listening url will be http://localhost:/mcp

  #### Parameters

  - transport: MCPTransport

    The transport for the MCP server

  - port: number = 3388

    The port for the MCP server (when using SSE transport)

  #### Returns Promise<string>

  MCP instance

  #### Example

      const agent = new Agent({ /* ... agent settings ... */ });

      const stdioMcp = agent.mcp(MCPTransport.STDIO);
      const sseMcp = agent.mcp(MCPTransport.SSE, 3389);

  - Defined in src/Agent/Agent.class.ts:991

### off

- off(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.off

  - Defined in src/Core/SDKObject.class.ts:49

### on

- on(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.on

  - Defined in src/Core/SDKObject.class.ts:41

### once

- once(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.once

  - Defined in src/Core/SDKObject.class.ts:53

### prompt

- prompt(prompt: string, options?: any): AgentCommand

  Send a prompt to the agent and get a response.

  The returned command can be executed in multiple ways:

  - Promise mode: `await agent.prompt("question")` - returns final result
  - Explicit execution: `await agent.prompt("question").run()` - same as above
  - Streaming mode: `await agent.prompt("question").stream()` - returns event emitter

  #### Parameters

  - prompt: string

    The message or question to send to the agent

  - `Optional` options: any

  #### Returns AgentCommand

  AgentCommand that can be executed or streamed

  #### Example

      // Simple prompt (promise mode)
      const answer = await agent.prompt("What is the capital of France?");

      // Streaming for long responses
      const stream = await agent.prompt("Write a detailed report").stream();
      stream.on('data', chunk => console.log(chunk));
      stream.on('end', () => console.log('Complete!'));

  - Defined in src/Agent/Agent.class.ts:904

### removeListener

- removeListener(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.removeListener

  - Defined in src/Core/SDKObject.class.ts:56

### removeSkill

- removeSkill(skillName: string): void

  Remove a skill from the agent.

  #### Parameters

  - skillName: string

    The name of the skill to remove

  #### Returns void

  The removed skill

  #### Example

      agent.removeSkill('fetch_weather');

  - Defined in src/Agent/Agent.class.ts:814

### setMode

- setMode(mode: TAgentMode): void

  Set the operational mode of the agent. an operational mode is a set of skills that are applied to the agent to change its behavior.

  #### Parameters

  - mode: TAgentMode

    The mode to apply, currently only "planner" is supported

  #### Returns void

  #### Example

      agent.setMode(TAgentMode.PLANNER);

  - Defined in src/Agent/Agent.class.ts:1007

### sync

- sync(): void

  #### Returns void

  - Defined in src/Agent/Agent.class.ts:469

### unsetMode

- unsetMode(mode: TAgentMode): void

  Remove the operational mode of the agent.

  #### Parameters

  - mode: TAgentMode

    The mode to remove

  #### Returns void

  #### Example

      agent.unsetMode(TAgentMode.PLANNER);

  - Defined in src/Agent/Agent.class.ts:1026

### `Static` import

- import(data: TAgentSettings): Agent

  Import an agent from a file or configuration object.

  Supported import patterns:

  - Import from `.smyth` file: `Agent.import('/path/to/agent.smyth')`
  - Import from configuration: `Agent.import(settingsObject)`
  - Import with overrides: `Agent.import('/path/to/agent.smyth', overrides)`

  #### Parameters

  - data: TAgentSettings

    File path or agent settings object

  #### Returns Agent

  New Agent instance

  #### Example

      // Import from file
      const agent1 = Agent.import('./my-agent.smyth');

      // Import from configuration object
      const agent2 = Agent.import({
        name: "Imported Agent",
        model: "gpt-4"
      });

      // Import with overrides
      const agent3 = Agent.import('./base-agent.smyth', {
        name: "Customized Agent",
        behavior: "Custom behavior override"
      });

  - Defined in src/Agent/Agent.class.ts:516
- import(data: string, overrides?: any): Agent

  Import an agent from a file or configuration object.

  Supported import patterns:

  - Import from `.smyth` file: `Agent.import('/path/to/agent.smyth')`
  - Import from configuration: `Agent.import(settingsObject)`
  - Import with overrides: `Agent.import('/path/to/agent.smyth', overrides)`

  #### Parameters

  - data: string

    File path or agent settings object

  - `Optional` overrides: any

    Optional settings to override imported configuration

  #### Returns Agent

  New Agent instance

  #### Example

      // Import from file
      const agent1 = Agent.import('./my-agent.smyth');

      // Import from configuration object
      const agent2 = Agent.import({
        name: "Imported Agent",
        model: "gpt-4"
      });

      // Import with overrides
      const agent3 = Agent.import('./base-agent.smyth', {
        name: "Customized Agent",
        behavior: "Custom behavior override"
      });

  - Defined in src/Agent/Agent.class.ts:517