Class: ComposableAgents::AiAgents::Agent

Inherits:
PromptDrivenAgent show all
Defined in:
lib/composable_agents/ai_agents/agent.rb

Overview

Agent implementation that uses an ai-agent's AgentRunner.

Instance Attribute Summary

Attributes inherited from PromptDrivenAgent

#constraints, #conversation, #objective, #role, #system_instructions

Attributes inherited from ComposableAgents::Agent

#name

Public API collapse

Methods inherited from PromptDrivenAgent

#run

Methods included from Mixins::Logger

debug?

Internal collapse

Methods inherited from PromptDrivenAgent

#input_artifacts_contracts, #output_artifacts_contracts, #report_error_for_output_artifact, #save_output_artifact

Methods inherited from ComposableAgents::Agent

#run

Constructor Details

#initialize(*args, model: Agents.configuration.default_model, params: {}, handoff_agents: [], **kwargs) ⇒ Agent

Initialize a new agent with a list of ai-agents' Agents to be used with an AgentRunner

Parameters:

  • model (String) (defaults to: Agents.configuration.default_model)

    Model to be used

  • params (Hash{Symbol => Object}) (defaults to: {})

    Additional parameters to give to the ai-agents' agent

  • handoff_agents (Array<Agents::Agent>) (defaults to: [])

    The list of additional agents that can be used for handoffs.



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

def initialize(
  *args,
  model: Agents.configuration.default_model,
  params: {},
  handoff_agents: [],
  **kwargs
)
  super(*args, **kwargs)
  @model = model
  @params = params
  @handoff_agents = handoff_agents
  @context = {}
end

Instance Method Details

#export_stateObject

Export the agent state for persistence

Returns:

  • (Object)

    Serialized state that can be marshalled to JSON



44
45
46
# File 'lib/composable_agents/ai_agents/agent.rb', line 44

def export_state
  super.merge(deep_transform_keys(context: Base64.encode64(Marshal.dump(@context)), &:to_s))
end

#full_nameString

Return the full name of the agent. This method is intended to be overridden by subclasses to give better full names, tailored to the kind of agent. The full name can be used in logs and traces to better identify the agent.

Returns:

  • (String)

    The agent's full name



35
36
37
# File 'lib/composable_agents/ai_agents/agent.rb', line 35

def full_name
  "#{name || 'Unnamed'} (AiAgent #{@model})"
end

#import_state(state) ⇒ Object

Import the agent state from persistence

Parameters:

  • state (Object)

    Serialized state



51
52
53
54
# File 'lib/composable_agents/ai_agents/agent.rb', line 51

def import_state(state)
  super
  @context = Marshal.load(Base64.decode64(deep_transform_keys(state, &:to_sym)[:context]))
end