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/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/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/skills/load_skill_tool.rb,
lib/ask/agent/stream_transforms/base.rb,
lib/ask/agent/extensions/rate_limiter.rb,
lib/ask/agent/extensions/permission_gate.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, Events, Extensions, Middleware, Persistence, Skills, StreamTransforms, Test Classes: Aborted, Chat, ChatChunk, CompactionFailed, Compactor, Configuration, Definition, Error, Hooks, Loop, LoopDetected, MaxTurnsExceeded, MetaAgent, Reflector, ResponseMessage, Scheduler, SchedulerConfig, Session, SessionNotPersisted, Telemetry, ToolAbortController, ToolCallInfo, ToolExecutionError, ToolExecutor, UnknownAgent

Constant Summary collapse

VERSION =
"0.8.0"

Class Method Summary collapse

Class Method Details

.configurationObject

Register the global config



195
196
197
# File 'lib/ask/agent.rb', line 195

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

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

Yields:



199
200
201
# File 'lib/ask/agent.rb', line 199

def self.configure
  yield configuration
end

.default_agent_pathsObject

Paths where agent directories are discovered.



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

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]



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

def definitions
  discover!
  @registry.dup
end

.load_extensionsObject



203
204
205
206
# File 'lib/ask/agent.rb', line 203

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:



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

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.



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

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.



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

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