Class: Kernai::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/kernai/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instructions:, provider: nil, model: Models::TEXT_ONLY, max_steps: 10, skills: nil, protocols: nil, generation: nil) ⇒ Agent

‘protocols` is a whitelist of Protocol block types this agent may address:

nil  → all registered protocols are allowed (default)
[]   → no protocol is allowed (explicit opt-out)
[:mcp, :a2a] → only the named protocols are allowed

‘generation` is a Kernai::GenerationOptions describing provider-agnostic generation knobs (temperature, max_tokens, top_p, thinking, and vendor-specific extras). Accepts `nil`, a Hash, or an existing GenerationOptions instance.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kernai/agent.rb', line 17

def initialize(instructions:, provider: nil, model: Models::TEXT_ONLY, max_steps: 10, skills: nil,
               protocols: nil, generation: nil)
  raise ArgumentError, 'model: must be a Kernai::Model' unless model.is_a?(Model)

  @instructions = instructions
  @provider = provider
  @model = model
  @max_steps = max_steps
  @skills = skills
  @protocols = protocols
  @generation = GenerationOptions.coerce(generation)
end

Instance Attribute Details

#generationObject (readonly)

Returns the value of attribute generation.



5
6
7
# File 'lib/kernai/agent.rb', line 5

def generation
  @generation
end

#instructionsObject

Returns the value of attribute instructions.



6
7
8
# File 'lib/kernai/agent.rb', line 6

def instructions
  @instructions
end

#max_stepsObject (readonly)

Returns the value of attribute max_steps.



5
6
7
# File 'lib/kernai/agent.rb', line 5

def max_steps
  @max_steps
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/kernai/agent.rb', line 5

def model
  @model
end

#protocolsObject

Returns the value of attribute protocols.



6
7
8
# File 'lib/kernai/agent.rb', line 6

def protocols
  @protocols
end

#providerObject

Returns the value of attribute provider.



6
7
8
# File 'lib/kernai/agent.rb', line 6

def provider
  @provider
end

#skillsObject

Returns the value of attribute skills.



6
7
8
# File 'lib/kernai/agent.rb', line 6

def skills
  @skills
end

Instance Method Details

#resolve_instructions(workflow_enabled: true) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/kernai/agent.rb', line 30

def resolve_instructions(workflow_enabled: true)
  InstructionBuilder.new(
    @instructions,
    model: @model,
    skills: @skills,
    protocols: @protocols,
    workflow_enabled: workflow_enabled
  ).build
end

#update_instructions(text) ⇒ Object



40
41
42
# File 'lib/kernai/agent.rb', line 40

def update_instructions(text)
  @instructions = text
end