Module: ComposableAgents::Mixins::ArtifactContract

Included in:
Cline::Agent
Defined in:
lib/composable_agents/mixins/artifact_contract.rb

Overview

Mixin providing input/output artifact validation functionality for Agents. The contracts should be provided by methods named #input_artifacts_contracts and #output_artifacts_contracts A contract can be one of the following objects:

  • [String] The artifact's description
  • [Hash{Symbol => Object}] The artifact's detailed contract. It can contain the following attributes:
    • description [String] The artifact's description. This is also the default value when the contract is expressed as a [String].
    • optional [Boolean] Is the artifact optional? Defaults to false.
    • type [Symbol] The type of this artifact. Defaults to :text. Possible values are:
      • text for raw text.
      • markdown for Markdown.
      • json for JSON. Type can be used by some agents to tailor their output format and prompts.

Defined Under Namespace

Classes: ArtifactTypeError, MissingInputArtifactError, MissingOutputArtifactError

Public API collapse

Internal collapse

Instance Method Details

#initialize(*args, input_artifacts_contracts: nil, output_artifacts_contracts: nil, **kwargs) ⇒ Object

Constructor

Parameters:

  • input_artifacts_contracts (Hash{Symbol => Object}, nil) (defaults to: nil)

    Hash of input artifact names and their contracts, or nil if provided through the input_artifacts_contracts method

  • output_artifacts_contracts (Hash{Symbol => Object}, nil) (defaults to: nil)

    Hash of output artifact names and their contracts, or nil if provided through the output_artifacts_contracts method



39
40
41
42
43
44
45
46
47
48
# File 'lib/composable_agents/mixins/artifact_contract.rb', line 39

def initialize(
  *args,
  input_artifacts_contracts: nil,
  output_artifacts_contracts: nil,
  **kwargs
)
  super(*args, **kwargs)
  @input_artifacts_contracts = input_artifacts_contracts
  @output_artifacts_contracts = output_artifacts_contracts
end

#run(**input_artifacts) ⇒ Hash{Symbol => Object}

Execute the agent to generate some output artifacts based on some input artifacts.

Parameters:

  • input_artifacts (Hash{Symbol => Object})

    The input artifacts content

Returns:

  • (Hash{Symbol => Object})

    Output artifacts content

Raises:



58
59
60
61
62
63
# File 'lib/composable_agents/mixins/artifact_contract.rb', line 58

def run(**input_artifacts)
  validate_input_artifacts(input_artifacts)
  output_artifacts = super(**input_artifacts.slice(*normalized_input_artifacts_contracts.keys))
  validate_output_artifacts(output_artifacts)
  output_artifacts
end