Class: Insika::Commands::CreateAgent
- Inherits:
-
Object
- Object
- Insika::Commands::CreateAgent
- Defined in:
- lib/insika/commands/create_agent.rb
Overview
Control command: creates an agent (AgentProfile) at RUNTIME and persists it in the ProfileSource (ConfigStore). This is the "everyone creates their own BIA". Synchronous; does not create a Task. -> AgentProfile (round-tripped from the store).
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(profile_source:, event_stream:) ⇒ CreateAgent
constructor
A new instance of CreateAgent.
Constructor Details
#initialize(profile_source:, event_stream:) ⇒ CreateAgent
Returns a new instance of CreateAgent.
11 12 13 14 |
# File 'lib/insika/commands/create_agent.rb', line 11 def initialize(profile_source:, event_stream:) @profile_source = profile_source @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/insika/commands/create_agent.rb', line 16 def call(command) attrs = AgentPayload.attrs(command.payload) id = AgentPayload.presence(attrs[:id]) raise Insika::ValidationError, "id is required" if id.nil? # model is OPTIONAL as of v2 (§10): omitted -> resolves the platform # default_model (Settings) at turn start. An agent with neither its own # model nor a platform default fails clearly at the first turn. raise Insika::ValidationError, "agent '#{id}' already exists" if @profile_source.fetch(id) profile = Insika::AgentProfile.build(**attrs) # RFC-0010 §4.4: definition-time cycle + depth check. Only a profile that # introduces edges (non-empty subagents) can create a violation — a # childless agent is always a safe leaf. Raises SubagentError (a # ValidationError) BEFORE persisting, so a bad graph never lands. validate_subagent_graph!(profile) @profile_source.put(profile) emit(:agent_created, id) @profile_source.fetch(id) # returns the persisted profile (symbols already normalized) end |