Module: Protege::ResolverMixin

Included in:
Resolver
Defined in:
lib/protege/extensions/resolver_mixin.rb

Overview

Contract mixin for resolver classes. A resolver receives a Context and returns an Array<Protege::ModelMessage> (one or more messages to prepend to the inference request) or nil to contribute nothing. Resolvers are the Orchestrator's mechanism for assembling inference context — system prompts, conversation history, retrieved knowledge.

Unlike Tool, resolvers are NOT auto-registered. They are explicitly added to a persona's ResolverChain at declaration time. Host resolvers subclass Protege::Resolver, which includes this module.

The role of returned messages is the developer's choice:

  • role: :system → contributes to the system prompt
  • role: :user / :assistant → contributes to conversation history

Build messages with the #message helper rather than constructing Protege::ModelMessage by hand — the resolver counterpart of +Tool+'s +success+/+failure+ sugar:

Examples:

class MyResolver < Protege::Resolver
  def resolve(context:)
    message(role: :system, content: "You are #{context.persona.name}.")
  end
end

Instance Method Summary collapse

Instance Method Details

#message(role:, content:, tool_call_id: nil, tool_calls: nil) ⇒ Protege::ModelMessage

Build one context message to contribute from #resolve, without constructing Protege::ModelMessage by hand — the resolver counterpart of +Tool+'s +success+/+failure+ sugar.

Return the message directly (a lone message) or collect several in an array; the ResolverChain coerces either shape and skips a nil return, so a resolver that contributes nothing just returns nil.

Examples:

a system prompt

message(role: :system, content: summary.to_prompt)

Parameters:

  • role (Symbol)

    :system (prompt), :user / :assistant (history), or :tool (a replayed tool result)

  • content (String, Array)

    the text, or multimodal parts (+TextPart+ / ImagePart / DocumentPart)

  • tool_call_id (String, nil) (defaults to: nil)

    correlates a role: :tool message back to its originating call

  • tool_calls (Array, nil) (defaults to: nil)

    the tool calls carried by a role: :assistant message

Returns:



54
55
56
# File 'lib/protege/extensions/resolver_mixin.rb', line 54

def message(role:, content:, tool_call_id: nil, tool_calls: nil)
  Protege::ModelMessage.new(role:, content:, tool_call_id:, tool_calls:)
end

#resolve(context:) ⇒ Array<Object>?

Produce context messages for the inference request. Concrete resolvers must override.

Parameters:

Returns:

  • (Array<Object>, nil)

    messages to prepend, or nil to contribute nothing

Raises:

  • (NotImplementedError)

    always, when not overridden by the including class



32
33
34
35
# File 'lib/protege/extensions/resolver_mixin.rb', line 32

def resolve(context:)
  raise NotImplementedError,
        "#{self.class} must implement #resolve(context:) -> Array<ModelMessage> | nil"
end