Interface AgencyInstance<R>

What agency() returns: the Agency interface with typed results. Assignable to Agency.

interface AgencyInstance<R> {
    session(id?): unknown;
    usage(sessionId?): Promise<unknown>;
    close(): Promise<void>;
    listen?(opts?): Promise<{
        port: number;
        url: string;
        close: (() => Promise<void>);
    }>;
    connect?(): Promise<void>;
    export?(metadata?, options?): unknown;
    exportJSON?(metadata?, options?): string;
    generate(prompt, opts?): Promise<R>;
    stream(prompt, opts?): AgencyStreamResult<R> & {
        result: Promise<R>;
    };
}

Type Parameters

Hierarchy (view full)

Methods

  • Returns (or creates) a named conversation session.

    Parameters

    • Optional id: string

      Optional session identifier; auto-generated when omitted.

    Returns unknown

    The session object for this ID.

  • Returns cumulative usage totals for the agent or a specific session.

    Parameters

    • Optional sessionId: string

      Optional session filter.

    Returns Promise<unknown>

  • Releases all in-memory state held by this agent.

    Returns Promise<void>

  • Starts a loopback WebSocket listener on 127.0.0.1 that exchanges JSON text: { "text": "..." } in, { "text": "..." } out, one request at a time per connection. It performs no speech recognition or synthesis; a binary frame receives an audio_not_supported error and close code 1003. Present on agency instances created with voice: { enabled: true }. Spoken calls use VoiceSessionFactory.

    Parameters

    • Optional opts: {
          port?: number;
      }

      Listener options; port 0, the default, picks a free port.

      • Optional port?: number

    Returns Promise<{
        port: number;
        url: string;
        close: (() => Promise<void>);
    }>

    Resolves to the bound port, URL, and a close() teardown function.

  • Connects the agent to configured channel adapters (e.g. Discord, Slack). Present on agency instances only.

    Returns Promise<void>

  • Exports the agent's full configuration as a portable object.

    The returned AgentExportConfig (imported from ./agentExport.js) can be serialized to JSON or YAML and re-imported via importAgent().

    Parameters

    • Optional metadata: Record<string, unknown>

      Optional human-readable metadata to attach.

    • Optional options: {
          redactSecrets?: boolean;
      }

      Redaction options; secrets are redacted unless redactSecrets is false.

      • Optional redactSecrets?: boolean

    Returns unknown

    A portable config object.

  • Exports the agent's full configuration as a pretty-printed JSON string.

    Parameters

    • Optional metadata: Record<string, unknown>

      Optional human-readable metadata to attach.

    • Optional options: {
          redactSecrets?: boolean;
      }

      Redaction options; secrets are redacted unless redactSecrets is false.

      • Optional redactSecrets?: boolean

    Returns string

    JSON string with 2-space indentation.

  • Parameters

    • prompt: string
    • Optional opts: Record<string, unknown>

    Returns Promise<R>