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

Parameters:

  • strategy (Module) (defaults to: PromptRenderingStrategy::MarkdownHeavy)

    The prompt rendering strategy

  • provider (String) (defaults to: 'cline')

    Provider to be used

  • model (String) (defaults to: 'anthropic/claude-sonnet-4.6')

    Model to be used

  • api_key (String) (defaults to: ENV.fetch('CLINE_API_KEY', nil))

    API key to be used

  • configure_provider (#call(provider_settings), nil) (defaults to: nil)

    Optional block used to configure the provider settings

    • Param provider_settings [Cline::Providers::ProviderSettings] Settings that can be tuned for this agent
  • configure_global (#call(global_settings), nil) (defaults to: nil)

    Optional block used to configure the global settings

    • Param global_settings [Cline::GlobalSettings] Settings that can be tuned for this agent
  • skills (Array<String>) (defaults to: [])

    List of skills to allow for this agent

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

    Task options to give to Cline CLI (see Cline::Cli.COMMANDS)



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

Returns:

  • (Object)

    Serialized state that can be marshalled to JSON



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.

Returns:

  • (String)

    The agent's full name



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

Parameters:

  • state (Object)

    Serialized state



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).

Parameters:

  • user_instructions (Object, nil) (defaults to: nil)

    Instructions for the user prompt, that will be rendered. The kind of instructions that can be given are defined by the Instructions's constructor (see Instructions#initialize).

  • input_artifacts (Hash{Symbol => Object})

    The input artifacts content, per artifact name

Returns:

  • (Hash{Symbol => Object})

    The output artifacts



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