Class: Insika::DSL::Runtime
- Inherits:
-
Object
- Object
- Insika::DSL::Runtime
- Defined in:
- lib/insika/dsl/runtime.rb
Overview
The live graph behind a Definition: it assembles the SAME authoring graph a concrete deployment does (Insika::Wiring::Graph + the runtime-authoring command surface), configures RubyLLM, and imports the definition's pack via the standard PackImporter. From there the agent is indistinguishable from one provisioned by any other pack — chat and serve just drive the normal path.
Built lazily by Definition#runtime, so require "insika" never pays for
ruby_llm or the HTTP server.
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one).
-
#llm ⇒ Object
readonly
The graph's RubyLLM context — an isolated config dup that answers #chat.
-
#pack ⇒ Object
readonly
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one).
-
#packs ⇒ Object
readonly
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one).
Instance Method Summary collapse
-
#chat(message, session_id: nil, timeout: nil, agent: nil) ⇒ Object
One turn, in-process → the assistant's text.
-
#component(name) ⇒ Object
A named collaborator (settings_store, tool_store, …) the server boot reads.
-
#initialize(definition, backend: nil) ⇒ Runtime
constructor
definitionis a Definition (one agent) or a System (N agents). -
#profile(agent_id = nil) ⇒ Object
An imported profile, read back from the store (config-over-code round-trip).
-
#run_workflow(name, input:, agent:, timeout: nil) ⇒ Object
Triggers a declared workflow and returns its OUTPUT (the typed value the workflow returned), not the turn text.
-
#serve(port:, host:, token:, **_opts) ⇒ Object
Boot the control UI (/studio) + drop-in API (/v1).
Constructor Details
#initialize(definition, backend: nil) ⇒ Runtime
definition is a Definition (one agent) or a System (N agents). Both
answer #pack/#id; a System also answers #packs. Duck-typed on purpose:
the runtime does not care how many agents it hosts, only that each one
arrives as an ordinary Pack.
backend: the store this graph owns. nil = the historic
path, INSIKA_DB or memory — ENV is a default, never a requirement (the
embed contract). An injected backend wins and is never widened
back to the environment.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/insika/dsl/runtime.rb', line 31 def initialize(definition, backend: nil) @definition = definition @injected_backend = backend @packs = (definition.respond_to?(:packs) ? Array(definition.packs) : [definition.pack]).freeze @pack = @packs.first # the graph's OWN RubyLLM config, built before the graph so # every collaborator that talks to a provider is handed it at wiring time # rather than reading a process-wide singleton at call time. @llm = build_llm_context @graph = build_graph # the dispatch+drain seam `#chat`/`#run_workflow` delegate to — # `Insika::Wiring::GraphChat`, shared with `config/deployment.rb`'s own # registration of `run_persona_eval` (see `register_persona_eval_tool` # below). @chat_runtime = Insika::Wiring::GraphChat.new(graph: @graph) seed_default_model import_packs end |
Instance Attribute Details
#graph ⇒ Object (readonly)
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one). All read by the server boot and the specs.
20 21 22 |
# File 'lib/insika/dsl/runtime.rb', line 20 def graph @graph end |
#llm ⇒ Object (readonly)
The graph's RubyLLM context — an isolated config dup that answers #chat. nil only under the test stub, where the fallback is the RubyLLM constant itself. Read by the specs and by anything a host wires alongside this graph.
54 55 56 |
# File 'lib/insika/dsl/runtime.rb', line 54 def llm @llm end |
#pack ⇒ Object (readonly)
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one). All read by the server boot and the specs.
20 21 22 |
# File 'lib/insika/dsl/runtime.rb', line 20 def pack @pack end |
#packs ⇒ Object (readonly)
graph: the assembled Wiring::Graph::Result; pack: the PRIMARY imported Pack; packs: every imported Pack (one per agent — a System has N, a Definition has one). All read by the server boot and the specs.
20 21 22 |
# File 'lib/insika/dsl/runtime.rb', line 20 def packs @packs end |
Instance Method Details
#chat(message, session_id: nil, timeout: nil, agent: nil) ⇒ Object
One turn, in-process → the assistant's text. session_id nil = stateless
one-shot; a value threads multi-turn memory (created on first use).
agent: targets one agent of a system (default: the primary).
67 68 69 70 |
# File 'lib/insika/dsl/runtime.rb', line 67 def chat(, session_id: nil, timeout: nil, agent: nil) @chat_runtime.chat(, agent: (agent || @definition.id).to_s, session_id: session_id, timeout: timeout) end |
#component(name) ⇒ Object
A named collaborator (settings_store, tool_store, …) the server boot reads.
91 |
# File 'lib/insika/dsl/runtime.rb', line 91 def component(name) = @components.fetch(name) |
#profile(agent_id = nil) ⇒ Object
An imported profile, read back from the store (config-over-code round-trip). Defaults to the primary agent.
58 59 60 61 62 |
# File 'lib/insika/dsl/runtime.rb', line 58 def profile(agent_id = nil) id = (agent_id || @definition.id).to_s @graph.profiles.fetch(id) || (raise Insika::Error, "agent '#{id}' was not imported") end |
#run_workflow(name, input:, agent:, timeout: nil) ⇒ Object
Triggers a declared workflow and returns its OUTPUT (the typed value the workflow returned), not the turn text. A schema violation on the input raises here, synchronously, with no run created — same contract as POST /v1/workflows/:name.
76 77 78 79 80 81 82 |
# File 'lib/insika/dsl/runtime.rb', line 76 def run_workflow(name, input:, agent:, timeout: nil) command = Insika::Command.build( :trigger_workflow, { workflow: name, agent: agent, input: input }, transport: :cli ) outcome = @chat_runtime.run_command(command, session_id: nil, timeout: timeout) outcome.key?(:output) ? outcome[:output] : outcome[:text] end |
#serve(port:, host:, token:, **_opts) ⇒ Object
Boot the control UI (/studio) + drop-in API (/v1). Blocks on the reactor.
85 86 87 88 |
# File 'lib/insika/dsl/runtime.rb', line 85 def serve(port:, host:, token:, **_opts) require_relative "server_boot" ServerBoot.new(self, port: port, host: host, token: token).run end |