Optionalspec: Partial<AgentSpec>Optional initial spec data (for creating new agents or working with existing data)
OptionalcontextUser: UserInfoOptional context user (required for server-side operations)
Optionalprovider: IMetadataProviderCheck if this spec has unsaved changes.
True if there are unsaved changes, false otherwise
Check if this spec has been loaded from the database.
True if loaded from database, false if created in memory
Clear all tracked mutations
Get all mutations tracked during the last save operation
Array of mutations
Mark the spec as having changes.
Call this method after modifying the spec to indicate that changes need to be saved. The spec is automatically marked dirty when created with the constructor, but if you load a spec and then modify it, you should call this method.
InternalMark the spec as having been loaded from the database.
This is used internally when updating existing child agents to ensure the delete logic runs correctly. When a child agent is updated via saveChildSubAgent(), we create a new AgentSpecSync instance from the spec data (not loaded from DB), but we need to mark it as loaded so orphaned records are properly deleted.
Save the current spec to the database.
This will create new records or update existing ones based on whether IDs exist. The save operation is performed atomically - if any part fails, no changes are committed.
Validation is performed before saving. All entity-level validations defined in the database schema are executed, and any failures will prevent the save.
Whether to validate before saving (default: true)
Promise resolving to result with agent ID, success flag, and all mutations performed
Get a clean serializable version of the spec.
Returns a plain JavaScript object suitable for JSON serialization, API responses, or storage. This is useful when you need to send the agent spec over the wire or store it in a file.
Clean copy of the agent specification
StaticFromCreate a new agent spec from a raw specification.
This creates an in-memory AgentSpecSync instance from raw data. The agent is not saved to the database until SaveToDatabase is called.
The raw spec data conforming to AgentSpec interface
OptionalcontextUser: UserInfoOptional context user (required when saving server-side)
Optionalprovider: IMetadataProviderNew AgentSpecSync instance (not yet saved to database)
StaticLoadLoad an agent by name (must be unique).
Searches for an agent with the specified name and loads it. If multiple agents have the same name, an error is thrown. Agent names should be unique within the system for this method to work reliably.
The name of the agent to load
OptionalcontextUser: UserInfoOptional context user (required for server-side operations)
Whether to recursively load sub-agents (default: true)
Optionalprovider: IMetadataProviderPromise resolving to AgentSpecSync instance with loaded data
StaticLoadLoad an agent and its complete hierarchy from the database by ID.
This method efficiently loads the agent along with all its actions and sub-agents
using batched queries to minimize database round trips. When includeSubAgents is true,
it recursively loads the entire agent hierarchy.
The unique ID of the agent to load
OptionalcontextUser: UserInfoOptional context user (required for server-side operations)
Whether to recursively load all sub-agents (default: true)
Optionalprovider: IMetadataProviderPromise resolving to AgentSpecSync instance with loaded data
Create a new AgentSpecSync instance.
Note: This constructor is typically not called directly. Instead, use the static factory methods: