Module: Ask::Agent

Defined in:
lib/ask/agent.rb,
lib/ask/agent/cli.rb,
lib/ask/agent/chat.rb,
lib/ask/agent/loop.rb,
lib/ask/agent/test.rb,
lib/ask/agent/hooks.rb,
lib/ask/agent/events.rb,
lib/ask/agent/session.rb,
lib/ask/agent/version.rb,
lib/ask/agent/compactor.rb,
lib/ask/agent/evaluator.rb,
lib/ask/agent/reflector.rb,
lib/ask/agent/scheduler.rb,
lib/ask/agent/telemetry.rb,
lib/ask/agent/definition.rb,
lib/ask/agent/meta_agent.rb,
lib/ask/agent/configuration.rb,
lib/ask/agent/tool_executor.rb,
lib/ask/agent/context_source.rb,
lib/ask/agent/system_context.rb,
lib/ask/agent/context_sources.rb,
lib/ask/agent/middleware/base.rb,
lib/ask/agent/persistence/base.rb,
lib/ask/agent/middleware/pipeline.rb,
lib/ask/agent/extensions/audit_log.rb,
lib/ask/agent/middleware/log_calls.rb,
lib/ask/agent/persistence/in_memory.rb,
lib/ask/agent/tool_abort_controller.rb,
lib/ask/agent/extensions/permissions.rb,
lib/ask/agent/skills/load_skill_tool.rb,
lib/ask/agent/stream_transforms/base.rb,
lib/ask/agent/extensions/rate_limiter.rb,
lib/ask/agent/middleware/model_fallback.rb,
lib/ask/agent/stream_transforms/pipeline.rb,
lib/ask/agent/middleware/default_settings.rb,
lib/ask/agent/middleware/retry_on_failure.rb,
lib/ask/agent/stream_transforms/text_buffer.rb,
lib/ask/agent/stream_transforms/extract_json.rb,
lib/ask/agent/stream_transforms/thinking_separator.rb

Defined Under Namespace

Modules: CLI, ContextSources, Events, Extensions, Middleware, Persistence, Skills, StreamTransforms, Test Classes: Aborted, Chat, ChatChunk, CompactionFailed, Compactor, Configuration, ContextSource, Definition, Error, Evaluator, Hooks, Loop, LoopDetected, MaxTurnsExceeded, MetaAgent, Reflector, ResponseMessage, Scheduler, SchedulerConfig, Session, SessionNotPersisted, SystemContext, Telemetry, ToolAbortController, ToolCallInfo, ToolExecutionError, ToolExecutor, UnknownAgent

Constant Summary collapse

VERSION =
"0.15.0"

Class Method Summary collapse

Class Method Details

.configurationObject

Register the global config



209
210
211
# File 'lib/ask/agent.rb', line 209

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



213
214
215
# File 'lib/ask/agent.rb', line 213

def self.configure
  yield configuration
end

.default_agent_pathsObject

Paths where agent directories are discovered.



80
81
82
83
84
85
# File 'lib/ask/agent.rb', line 80

def default_agent_paths
  [
    File.join(Dir.pwd, "agents"),
    File.join(Dir.pwd, "app", "agents")
  ]
end

.definitionsHash<String, Array(Class, String)>

All discovered agent definitions, keyed by name. Triggers discovery on first call.

Returns:

  • (Hash<String, Array(Class, String)>)

    name → [Definition subclass, directory path]



54
55
56
57
# File 'lib/ask/agent.rb', line 54

def definitions
  discover!
  @registry.dup
end

.load_extensionsObject



217
218
219
220
# File 'lib/ask/agent.rb', line 217

def self.load_extensions
  Dir[File.expand_path("agent/extensions/*.rb", __dir__)].each { |f| require f }
rescue Errno::ENOENT
end

.new(name) ⇒ Session

Create a new agent session from a named definition.

Parameters:

  • name (String, Symbol)

    the agent name (directory name under agents/)

Returns:

  • (Session)

    a configured, ready-to-run session

Raises:



63
64
65
66
67
68
69
70
# File 'lib/ask/agent.rb', line 63

def new(name)
  discover!
  entry = @registry[name.to_s]
  raise UnknownAgent, "Unknown agent: #{name.inspect}. Searched agents/ and app/agents/." unless entry

  klass, dir = entry
  build_session_from_definition(klass, dir)
end

.rediscover!Object

Force re-discovery of agent definitions.



73
74
75
76
77
# File 'lib/ask/agent.rb', line 73

def rediscover!
  @discovered = false
  @registry = {}
  discover!
end

.resolve_tool_symbol(symbol) ⇒ Object

Resolve a tool symbol to a tool class. Checks the shared tools directory first, then falls back to the global tool registry from ask-tools.



90
91
92
93
94
95
96
# File 'lib/ask/agent.rb', line 90

def resolve_tool_symbol(symbol)
  @shared_tools[symbol.to_s] || begin
    Ask::Tools[symbol.to_s]
  rescue StandardError
    nil
  end
end