OSVauco/opax-mcp/emma_adapter.py

52 lines
1.9 KiB
Python

"""
Emma Adapter to provide a canonical, consistent interface to the Emma agent core.
"""
# This will be copied to /app/emma_identity.py by the Dockerfile
from emma_identity import get_runtime_system_prompt
class CanonicalEmma:
"""
A facade for the Emma agent that enforces a canonical identity and contract,
while allowing the underlying chat function to be injected as a dependency.
"""
def __init__(self, chat_function, model, system_prompt=None):
"""
Initializes the CanonicalEmma adapter.
Args:
chat_function: The async function to call for the LLM interaction.
model: The name of the model to use.
system_prompt: An optional system prompt to override the default.
"""
self._chat_function = chat_function
self._model = model
self._system_prompt = system_prompt or get_runtime_system_prompt()
async def run(self, prompt, history=None, system_context: str | None = None):
"""
Runs the Emma agent with the given prompt.
In Phase 1, this is a simple pass-through to the injected chat_function,
ensuring the canonical system prompt is used. History is ignored for now.
Args:
prompt: The user\'s prompt.
history: The conversation history (currently ignored).
system_context: Optional context to append to the system prompt.
Returns:
The raw dictionary response from the chat_function.
"""
# Phase 1 does not use history or memory.
composed_system_prompt = self._system_prompt
if system_context:
composed_system_prompt = f"{self._system_prompt}\n\n{system_context.strip()}"
return await self._chat_function(
self._model,
prompt,
composed_system_prompt,
history=history or [],
)