Skip to content

interlens.participant

interlens.participant

Participant

Bases: ABC

A participant in a conversation, either a model or a person.

A participant owns three things: an identity within the conversation (name + self_role/ others_role), its private framing (system_prompt + private_context — instructions/knowledge only it sees), and the ability to turn a rendered view into its next message (generate). The Conversation assembles the structured view from the shared transcript; the participant flattens that view to what its chat template expects via finalize_view and generates.

name instance-attribute

name: str

A name or identifier to uniquely identify this participant within a conversation.

finalize_view

finalize_view(segments: list[ViewSegment]) -> list[dict]

Flatten the structured, context-fitted view into the [{role, content}] list the chat template consumes. Applies family-specific repairs driven by the capability flags:

  • supports_system_role=False → fold the leading system content into the first user turn (Gemma's template errors on a standalone system role).
  • requires_alternating_roles=True → merge consecutive same-role segments (Gemma requires strict user/model alternation; the moderator seed + another speaker + private context can otherwise produce consecutive user turns that the template rejects). Merged turns keep author labels so speaker identity isn't lost in the concatenation.
Source code in src/interlens/participant/participant.py
def finalize_view(self, segments: list[ViewSegment]) -> list[dict]:
	"""Flatten the structured, context-fitted view into the ``[{role, content}]`` list the chat template
	consumes. Applies family-specific repairs driven by the capability flags:

	- ``supports_system_role=False`` → fold the leading system content into the first user turn (Gemma's
	  template errors on a standalone ``system`` role).
	- ``requires_alternating_roles=True`` → merge consecutive same-role segments (Gemma requires strict
	  user/model alternation; the moderator seed + another speaker + private context can otherwise produce
	  consecutive ``user`` turns that the template rejects). Merged turns keep author labels so speaker
	  identity isn't lost in the concatenation.
	"""
	segments = list(segments)
	if not self.supports_system_role:
		segments = self._fold_system_into_first_user(segments)
	if self.requires_alternating_roles:
		return self._merge_consecutive_same_role(segments)
	return [s.as_message() for s in segments]

generate abstractmethod

generate(
    view: list[dict],
    *,
    steering=None,
    capture=None,
    patch=None,
    return_logprobs: bool = False,
    turn: int | None = None,
    max_new_tokens: int | None = None
) -> Message

Produce this participant's next message given view — the conversation flattened to [{"role", "content"}] from this participant's perspective. Returns a Message it authored.

Interp options apply to local-model participants: steering (a SteeringSpec), capture (a CaptureRequest), patch (a Patch), and return_logprobs; turn is the message index used to tag captured activations. Participants that can't honor an interp request (e.g. API-backed) must raise rather than silently ignore it — a failed capture/steer must fail loudly.

Source code in src/interlens/participant/participant.py
@abstractmethod
def generate(self, view: list[dict], *, steering=None, capture=None, patch=None,
             return_logprobs: bool = False, turn: int | None = None,
             max_new_tokens: int | None = None) -> Message:
	"""Produce this participant's next message given ``view`` — the conversation flattened to
	``[{"role", "content"}]`` from this participant's perspective. Returns a ``Message`` it authored.

	Interp options apply to local-model participants: ``steering`` (a ``SteeringSpec``), ``capture`` (a
	``CaptureRequest``), ``patch`` (a ``Patch``), and ``return_logprobs``; ``turn`` is the message index used
	to tag captured activations. Participants that can't honor an interp request (e.g. API-backed) must raise
	rather than silently ignore it — a failed capture/steer must fail loudly."""
	...