Class: OllamaAgent::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/runner.rb

Overview

Stable public facade for library consumers. Configure via Runner.build, then call #run.

Examples:

runner = OllamaAgent::Runner.build(root: "/my/project", stream: true, audit: true)
runner.hooks.on(:on_token) { |p| print p[:token] }
runner.run("Refactor the auth module")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#session_idString? (readonly)

Returns the current session id.

Returns:

  • (String, nil)

    the current session id



22
23
24
# File 'lib/ollama_agent/runner.rb', line 22

def session_id
  @session_id
end

Class Method Details

.build(root: Dir.pwd, model: nil, system_prompt: nil, stream: false, session_id: nil, resume: false, max_tokens: nil, context_summarize: false, max_retries: nil, audit: nil, read_only: false, skills_enabled: true, skill_paths: nil, confirm_patches: true, orchestrator: false, think: nil, http_timeout: nil, stdin: $stdin, stdout: $stdout, provider: nil, credentials: nil, permissions: nil, budget: nil, memory: nil, trace: false, logger: nil) ⇒ Runner

Build a configured Runner.

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength – library facade must expose all Agent options

Parameters:

  • root (String) (defaults to: Dir.pwd)

    project root directory (default: Dir.pwd)

  • model (String, nil) (defaults to: nil)

    Ollama model name

  • system_prompt (String, nil) (defaults to: nil)

    custom system prompt override

  • stream (Boolean) (defaults to: false)

    enable streaming token output to stdout

  • session_id (String, nil) (defaults to: nil)

    named session for persistence

  • resume (Boolean) (defaults to: false)

    load prior session messages before running

  • max_retries (Integer) (defaults to: nil)

    HTTP retry attempts (0 = disable)

  • audit (Boolean) (defaults to: nil)

    enable structured audit logging

  • read_only (Boolean) (defaults to: false)

    disable write tools

  • skills_enabled (Boolean) (defaults to: true)

    include bundled prompt skills

  • skill_paths (Array<String>, nil) (defaults to: nil)

    extra .md skill paths

  • confirm_patches (Boolean) (defaults to: true)

    prompt before applying patches

  • orchestrator (Boolean) (defaults to: false)

    enable external agent delegation

  • think (String, nil) (defaults to: nil)

    thinking mode (true/false/high/medium/low)

  • http_timeout (Integer, nil) (defaults to: nil)

    HTTP timeout in seconds

  • stdin (IO) (defaults to: $stdin)

    input for patch/write/delegate confirmations (default $stdin)

  • stdout (IO) (defaults to: $stdout)

    output for confirmation prompts (default $stdout)

  • provider (String, nil) (defaults to: nil)

    provider name: “ollama” | “openai” | “anthropic” | “auto” (v2)

  • permissions (Runtime::Permissions, nil) (defaults to: nil)

    tool permission profile (v2)

  • budget (Core::Budget, nil) (defaults to: nil)

    token/step budget (v2)

  • memory (Memory::Manager, nil) (defaults to: nil)

    memory manager instance (v2)

  • trace (Boolean) (defaults to: false)

    enable trace logging to stdout (v2)

  • logger (Logger, nil) (defaults to: nil)

    stderr logger for agent warnings (default: new Logger on $stderr)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ollama_agent/runner.rb', line 51

def self.build(
  root:            Dir.pwd,
  model:           nil,
  system_prompt:   nil,
  stream:          false,
  session_id:      nil,
  resume:          false,
  max_tokens:      nil,
  context_summarize: false,
  max_retries:     nil,
  audit:           nil,
  read_only:       false,
  skills_enabled:  true,
  skill_paths:     nil,
  confirm_patches: true,
  orchestrator:    false,
  think:           nil,
  http_timeout:    nil,
  stdin:           $stdin,
  stdout:          $stdout,
  # v2 platform options
  provider:        nil,
  credentials:     nil, # Array<Hash> — multi-key credential pool config
  permissions:     nil,
  budget:          nil,
  memory:          nil,
  trace:           false,
  logger:          nil
)
  new(
    root: root, model: model, system_prompt: system_prompt, stream: stream,
    session_id: session_id, resume: resume,
    max_tokens: max_tokens, context_summarize: context_summarize,
    max_retries: max_retries, audit: audit, read_only: read_only,
    skills_enabled: skills_enabled, skill_paths: skill_paths,
    confirm_patches: confirm_patches, orchestrator: orchestrator,
    think: think, http_timeout: http_timeout,
    stdin: stdin, stdout: stdout,
    provider: provider, credentials: credentials,
    permissions: permissions,
    budget: budget, memory: memory, trace: trace,
    logger: logger
  )
end

Instance Method Details

#assign_chat_model!(name) ⇒ String

Assign a new chat model.

Parameters:

  • name (String)

Returns:

  • (String)


111
112
113
# File 'lib/ollama_agent/runner.rb', line 111

def assign_chat_model!(name)
  @agent.assign_chat_model!(name)
end

#hooksStreaming::Hooks

Returns the hooks bus — attach subscribers before calling #run.

Returns:

  • (Streaming::Hooks)

    the hooks bus — attach subscribers before calling #run



17
18
19
# File 'lib/ollama_agent/runner.rb', line 17

def hooks
  @agent.hooks
end

#modelString

Returns the active model.

Returns:

  • (String)

    the active model



104
105
106
# File 'lib/ollama_agent/runner.rb', line 104

def model
  @agent.model
end

#run(query) ⇒ Object

Execute a query. Blocks until the agent loop completes.

Parameters:

  • query (String)


99
100
101
# File 'lib/ollama_agent/runner.rb', line 99

def run(query)
  agent.run(query)
end