fix: langfuse v4 SDK compatibility and pass user message as trace input
This commit is contained in:
@@ -528,7 +528,9 @@ def _infer_floating_domain_rule_based(message: str, context: dict[str, Any]) ->
|
||||
return {"type": "task", "id": None, "section": None}
|
||||
|
||||
|
||||
async def _infer_floating_domain(message: str, context: dict[str, Any]) -> dict[str, str | None]:
|
||||
async def _infer_floating_domain(
|
||||
message: str, context: dict[str, Any], *, langfuse_handler: Any | None = None,
|
||||
) -> dict[str, str | None]:
|
||||
resolved_project_id = context.get("resolved_project_id") if isinstance(context, dict) else None
|
||||
project_id = resolved_project_id if isinstance(resolved_project_id, str) and resolved_project_id else None
|
||||
|
||||
@@ -538,10 +540,14 @@ async def _infer_floating_domain(message: str, context: dict[str, Any]) -> dict[
|
||||
}
|
||||
|
||||
try:
|
||||
llm = get_llm()
|
||||
classifier_prompt = _get_system_prompt(
|
||||
"floating_domain_classifier", _FLOATING_DOMAIN_CLASSIFIER_SYSTEM,
|
||||
)
|
||||
callbacks = _build_callbacks(langfuse_handler)
|
||||
llm = get_llm(callbacks=callbacks)
|
||||
response = await llm.ainvoke(
|
||||
[
|
||||
SystemMessage(content=_FLOATING_DOMAIN_CLASSIFIER_SYSTEM),
|
||||
SystemMessage(content=classifier_prompt),
|
||||
HumanMessage(
|
||||
content=(
|
||||
f"Message:\n{message}\n\n"
|
||||
@@ -784,7 +790,7 @@ async def run_home(user_id: str, message: str, context: dict[str, Any], *, langf
|
||||
|
||||
async def run_floating(user_id: str, message: str, context: dict[str, Any], *, langfuse_handler: Any | None = None) -> tuple[str, dict[str, str | None]]:
|
||||
prepared_context = await _prepare_context(message, context)
|
||||
domain = await _infer_floating_domain(message, prepared_context)
|
||||
domain = await _infer_floating_domain(message, prepared_context, langfuse_handler=langfuse_handler)
|
||||
system_prompt = _get_system_prompt("floating_system", _FLOATING_SINGLE_AGENT_SYSTEM)
|
||||
response = await _run_single_agent(
|
||||
user_id=user_id,
|
||||
@@ -835,7 +841,7 @@ async def run_floating_stream(
|
||||
langfuse_handler: Any | None = None,
|
||||
) -> AsyncGenerator[tuple[str, Any], None]:
|
||||
prepared_context = await _prepare_context(message, context)
|
||||
domain = await _infer_floating_domain(message, prepared_context)
|
||||
domain = await _infer_floating_domain(message, prepared_context, langfuse_handler=langfuse_handler)
|
||||
yield "floating_domain", domain
|
||||
|
||||
system_prompt = _get_system_prompt("floating_system", _FLOATING_SINGLE_AGENT_SYSTEM)
|
||||
|
||||
Reference in New Issue
Block a user