Function importAgent

  • Imports an agent from an AgentExportConfig object.

    For type: 'agent', calls the agent() factory with the stored config. For type: 'agency', calls the agency() factory with the stored config plus the sub-agent roster and strategy. The roster is read from agents; the copy inside config is dropped.

    Exports redact secrets and replace class instances by default, so import restores them: options.secrets maps the JSON Pointer of each redacted string to its value, and options.values maps the pointer of each <<instance>> marker (or dropped function) to the object to put there; only a non-empty string restores a secret, and an undefined or null value puts nothing back. A redacted provider key beside a model provider agentos knows, with no entry, resolves as an unset key does (an applicable setDefaultProvider() default, then the environment). A redacted baseUrl beside one, with no entry, is dropped when a default naming that provider carries a baseUrl or the provider's URL variable is set, each read as the agent's calls read it: an empty or whitespace-only one is unset, so a default with baseUrl: '' leaves the variable to apply, and neither lists the path. A roster seat's own key or URL, and a key beside any other provider, is listed.

    The document is copied in the serialized form (functions left out, class instances as markers), so importing the object form of an unredacted export lists its instances and drops its functions: pass them through values.

    Parameters

    Returns Agent

    A new Agent instance constructed from the config.

    Throws

    If the config is invalid, if the roster holds a pre-built seat, or if a redacted value or instance marker has no entry; the error lists every such path.

    Example

    const config = JSON.parse(fs.readFileSync('agent.json', 'utf-8'));
    const agent = importAgent(config, {
    secrets: { '/agents/support/channels/slack/credential': process.env.SLACK_BOT_TOKEN! },
    values: { '/config/router': myRouter },
    });
    const reply = await agent.generate('Hello!');