Respondent Prompt Modifiers

class afterimage.WithContextRespondentPromptModifier(prompt_template: str | None = None)[source]

Bases: BaseRespondentPromptModifierCallback

Modifies respondent prompt by adding context.

Parameters:

prompt_template – Custom prompt template. If None, uses default_respondent_prompt_with_context. If it contains {prompt} and/or {context}, they will be replaced by the respondent prompt and the context, respectively.

async agenerate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions asynchronously.

generate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions.

Parameters:
  • respondent_prompt – The original prompt for the respondent

  • context – Additional context to be included

  • instruction – The instruction associated with the prompt

Returns:

GeneratedResponsePrompt containing the modified prompt and context

class afterimage.WithRAGRespondentPromptModifier(retriever: ContextRetriever, prompt_template: str | None = None)[source]

Bases: WithContextRespondentPromptModifier

Modifies respondent prompt by adding relevant context using a retrieval strategy.

Uses afterimage.retrievers.aget_retrieval_result() / get_retrieval_result_sync so retrievers may optionally implement *_context_with_metadata and attach citation-style fields under GeneratedResponsePrompt.metadata[RETRIEVAL_METADATA_KEY].

Parameters:
  • retriever – Strategy for retrieving relevant context

  • prompt_template – Custom prompt template. If None, uses default_rag_respondent_prompt_with_context.

async agenerate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions asynchronously.

augment_context(instruction: str, current_context: str) str[source]

Augment existing context with relevant information using the retriever.

async augment_context_async(instruction: str, current_context: str) str[source]

Async RAG augmentation; uses the same resolution as agenerate().

generate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions.

Parameters:
  • respondent_prompt – The original prompt for the respondent

  • context – Additional context to be included

  • instruction – The instruction associated with the prompt

Returns:

GeneratedResponsePrompt containing the modified prompt and context