Class: ComposableAgents::Cline::Agent

Inherits:
PromptDrivenAgent show all
Includes:
Mixins::ArtifactContract
Defined in:
lib/composable_agents/cline/agent.rb

Overview

Agent implementation that uses an ai-agent's AgentRunner. This agent publishes the following run information:

  • usage [Hash] Cumulative usage of the API requests (cost and tokens) made during the run. This information is published in realtime, as soon as the Cline CLI reports API requests. Here are the properties it contains:
    • cost [Float] Cumulative monetary cost of all API requests of the run.
    • input_tokens [Integer] Cumulative number of input tokens of all API requests of the run.
    • output_tokens [Integer] Cumulative number of output tokens of all API requests of the run.
    • cache_read_tokens [Integer] Cumulative number of tokens read from cache by all API requests of the run.
    • cache_write_tokens [Integer] Cumulative number of tokens written to cache by all API requests of the run.
    • context_tokens [Integer, nil] Number of context tokens consumed by the last API request of the run. This property is not cumulative, as each API request contains the full context.
    • context_tokens_limit [Integer, nil] Maximum context window limit of the model used, or nil if unknown.

Instance Attribute Summary

Attributes inherited from PromptDrivenAgent

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

Attributes inherited from Agent

#name, #runs_info

Public API collapse

Internal collapse

Methods inherited from PromptDrivenAgent

#input_artifacts_contracts, #output_artifacts_contracts, #report_error_for_output_artifact, #save_output_artifact

Constructor Details

#initialize(*args, strategy: PromptRenderingStrategy::MarkdownHeavy, provider: 'cline', model: 'anthropic/claude-sonnet-4.6', api_key: ENV.fetch('CLINE_API_KEY', nil), configure_provider: nil, configure_global: nil, skills: [], cli_options: {}, **kwargs) ⇒ Agent

Initialize a new agent that uses the Cline CLI in a dedicated config



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/composable_agents/cline/agent.rb', line 40

def initialize(
  *args,
  strategy: PromptRenderingStrategy::MarkdownHeavy,
  provider: 'cline',
  model: 'anthropic/claude-sonnet-4.6',
  api_key: ENV.fetch('CLINE_API_KEY', nil),
  configure_provider: nil,
  configure_global: nil,
  skills: [],
  cli_options: {},
  **kwargs
)
  super(*args, strategy:, **kwargs)
  @provider = provider
  @model = model
  @api_key = api_key ? ::Cline::SecretString.new(api_key.dup) : nil
  @configure_provider = configure_provider
  @configure_global = configure_global
  @skills = skills
  @cli_options = cli_options
  @context = []
end

Instance Method Details

#export_stateObject

Export the agent state for persistence



89
90
91
# File 'lib/composable_agents/cline/agent.rb', line 89

def export_state
  super.merge(deep_transform_keys(context: @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.



68
69
70
# File 'lib/composable_agents/cline/agent.rb', line 68

def full_name
  "#{name || 'Unnamed'} (Cline #{@provider}/#{@model})"
end

#import_state(state) ⇒ Object

Import the agent state from persistence



96
97
98
99
# File 'lib/composable_agents/cline/agent.rb', line 96

def import_state(state)
  super
  @context = deep_transform_keys(state, &:to_sym)[:context]
end

#run(user_instructions: nil, **input_artifacts) ⇒ Hash{Symbol => Object}

Execute the agent to generate some output artifacts based on some input artifacts. Also reset the usage statistics accumulated for this run (published realtime in the run info).



79
80
81
82
# File 'lib/composable_agents/cline/agent.rb', line 79

def run(user_instructions: nil, **input_artifacts)
  @usage_by_ts = {}
  super
end