prompt_context

Async context builder for system-prompt template variables.

Gathers runtime data from the incoming message, platform adapter, bot configuration, and (optionally) Redis to produce the full dictionary that PromptRenderer feeds into the Jinja2 template.

prompt_context.format_mention(user_id, platform)[source]

Format a user mention appropriate for platform.

Discord uses <@USER_ID>; Matrix user IDs (@user:server) are already display-ready.

Return type:

str

Parameters:
  • user_id (str)

  • platform (str)

class prompt_context.PromptContextBuilder(config, kg_manager=None, threadweave_manager=None, status_manager=None, message_cache=None, task_manager=None, conversation_manager=None, openrouter_client=None)[source]

Bases: object

Build the template-variable dict consumed by the system prompt.

Parameters:
  • config (Config) – The global Config instance (provides model, redis_url, etc.).

  • kg_manager (KnowledgeGraphManager | None) – Optional KnowledgeGraphManager for injecting knowledge graph context into the system prompt. None when Redis is not configured.

  • threadweave_manager (ThreadweaveManager | None)

  • status_manager (Any | None)

  • message_cache (MessageCache | None)

  • task_manager (TaskManager | None)

  • conversation_manager (ConversationManager | None)

  • openrouter_client (Any | None)

__init__(config, kg_manager=None, threadweave_manager=None, status_manager=None, message_cache=None, task_manager=None, conversation_manager=None, openrouter_client=None)[source]

Initialize the instance.

Parameters:
Return type:

None

async build(msg, platform, query_embedding=None)[source]

Collect every context section and return a merged dict.

Sections that depend on Redis silently return empty values when Redis is not configured. Sections that depend on Discord- specific data gracefully degrade on other platforms.

Return type:

dict[str, Any]

Parameters:
build_minimal(msg, platform)[source]

Return a context dict using only synchronous, I/O-free sections.

Guarantees every unconditional template variable is present so the Jinja2 renderer never receives a bare Undefined object. Used as the fallback when the full async build() call times out or raises an unexpected exception.

Return type:

dict[str, Any]

Parameters: