Class: Insika::DSL::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/dsl/definition.rb

Overview

The result of Insika.agent("id") { … }. Holds the generated Pack and knows how to run it — but stays gem-free until you actually chat/serve/introspect: the runtime (ruby_llm + the HTTP server) is required lazily inside Runtime.

Every runtime path goes through the SAME config-over-code import: the pack is imported (create_agent + write_agent_file/skill/data_tool) into a StoredProfileSource, exactly like any other pack. That is what makes #profile identical to a hand-written equivalent pack (the parity spec) — there is only one path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pack:, runtime: {}) ⇒ Definition

Returns a new instance of Definition.



16
17
18
19
# File 'lib/insika/dsl/definition.rb', line 16

def initialize(pack:, runtime: {})
  @pack = pack
  @runtime_options = runtime
end

Instance Attribute Details

#packObject (readonly)

Returns the value of attribute pack.



14
15
16
# File 'lib/insika/dsl/definition.rb', line 14

def pack
  @pack
end

#runtime_optionsObject (readonly)

Returns the value of attribute runtime_options.



14
15
16
# File 'lib/insika/dsl/definition.rb', line 14

def runtime_options
  @runtime_options
end

Instance Method Details

#idObject



21
# File 'lib/insika/dsl/definition.rb', line 21

def id = pack.config[:id].to_s

#profileObject

The AgentProfile the engine runs, read back from the store after import — so it is byte-for-byte what a hand-written equivalent pack produces.



29
# File 'lib/insika/dsl/definition.rb', line 29

def profile = runtime.profile

#reply(message, session: nil, timeout: nil) ⇒ Object Also known as: chat

One turn, in-process, returns the assistant's text. session: threads multi-turn memory (a session is created on first use); omit it for a stateless one-shot. Raises on a failed/cancelled turn.



34
35
36
# File 'lib/insika/dsl/definition.rb', line 34

def reply(message, session: nil, timeout: nil)
  runtime.chat(message, session_id: session, timeout: timeout)
end

#runtimeObject

The live runtime graph (Executor + bus + stores) with the pack imported. Memoized: chat/serve/profile share one graph. Pulls in ruby_llm here.



47
48
49
50
51
52
# File 'lib/insika/dsl/definition.rb', line 47

def runtime
  @runtime ||= begin
    require_relative "runtime"
    Runtime.new(self)
  end
end

#serve(port: 9292, host: "localhost", token: nil, **opts) ⇒ Object

Boot the control UI (/studio) + the drop-in API (/v1) — the "1 command" of the quickstart. Blocks (runs the reactor) until interrupted.



41
42
43
# File 'lib/insika/dsl/definition.rb', line 41

def serve(port: 9292, host: "localhost", token: nil, **opts)
  runtime.serve(port: port, host: host, token: token, **opts)
end

#to_packObject

The generated portable artifact — hand it to any PackImporter and you get this same agent. This is the DSL's real output.



25
# File 'lib/insika/dsl/definition.rb', line 25

def to_pack = @pack