Skip to main content

Overview

Agent serialization lets you save agent configurations as JSON and reconstruct them later. Useful for persisting agent configs in databases, transferring between services, or version-controlling agent definitions.

Serialize

import { Agent, openai } from "@radaros/core";

const agent = new Agent({
  name: "my-agent",
  model: openai("gpt-4o"),
  instructions: "You are a helpful assistant",
  temperature: 0.7,
});

const json = agent.toJSON();
// {
//   name: "my-agent",
//   modelId: "gpt-4o",
//   providerId: "openai",
//   instructions: "You are a helpful assistant",
//   toolNames: [],
//   temperature: 0.7,
// }

Deserialize

import { Agent, openai } from "@radaros/core";

const registry = {
  models: {
    "gpt-4o": openai("gpt-4o"),
    "gpt-4o-mini": openai("gpt-4o-mini"),
  },
  tools: {
    search: searchTool,
    calculate: calcTool,
  },
};

const agent = Agent.fromJSON(savedJson, registry);
const output = await agent.run("Hello!");

SerializedAgent Schema

FieldTypeDescription
namestringAgent name
modelIdstringModel identifier
providerIdstringProvider identifier
instructionsstring?System instructions
toolNamesstring[]Tool names (resolved from registry)
temperaturenumber?Temperature setting
maxTokensnumber?Max output tokens
reasoningobject?Reasoning configuration

Notes

  • Function-based instructions are not serializable (only string instructions are saved)
  • Runtime objects (EventBus, storage) are stripped during serialization
  • Deserialized agents have register: false by default to avoid auto-registration