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.
- 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:
objectBuild the template-variable dict consumed by the system prompt.
- Parameters:
config (
Config) – The globalConfiginstance (providesmodel,redis_url, etc.).kg_manager (
KnowledgeGraphManager|None) – OptionalKnowledgeGraphManagerfor injecting knowledge graph context into the system prompt.Nonewhen 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:
config (
Config) – Bot configuration object.kg_manager (
KnowledgeGraphManager|None) – The kg manager value.threadweave_manager (
ThreadweaveManager|None) – The threadweave manager value.message_cache (
MessageCache|None) – The message cache value.task_manager (
TaskManager|None) – The task manager value.conversation_manager (
ConversationManager|None) – The conversation manager value.openrouter_client (
Any|None) – Shared OpenRouterClient for embedding connection pooling.
- 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:
- Parameters:
msg (IncomingMessage)
platform (PlatformAdapter)
query_embedding (ndarray | None)
- 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
Undefinedobject. Used as the fallback when the full asyncbuild()call times out or raises an unexpected exception.- Return type:
- Parameters:
msg (IncomingMessage)
platform (PlatformAdapter)