fix(tracing): use Langfuse compile_prompt with {{variable}} syntax

- tracing.py: add compile_prompt() that uses Langfuse .compile(**vars)
  for {{variable}} substitution, falls back to Python .format() for
  hardcoded {variable} templates
- agent_runner.py: replace _get_system_prompt().format() with
  tracing.compile_prompt() for batch_file_classifier, batch_processing,
  batch_cloud_processing prompts
- journey.py: replace get_prompt + .format() with compile_prompt()
  for journey_system prompt
- chat tracing.py: add compile_prompt() for parity (chat prompts
  currently have no variables, but ready for future use)
- Remove unused _get_system_prompt helper
This commit is contained in:
Roberto Musso
2026-03-23 22:39:27 +01:00
parent 55500cc818
commit ccba54ac24
4 changed files with 120 additions and 36 deletions

View File

@@ -145,15 +145,17 @@ def _build_system_prompt(
if existing_template
else ""
)
# Try Langfuse-managed prompt first, fall back to hardcoded template
managed = tracing.get_prompt("journey_system", fallback=None)
template = managed if managed is not None else _SYSTEM_PROMPT_TEMPLATE
return template.format(
directory=directory,
data_types=", ".join(data_types),
template_start=_TEMPLATE_START,
template_end=_TEMPLATE_END,
existing_section=existing_section,
# Use Langfuse compile_prompt ({{variable}} syntax) with Python .format() fallback
return tracing.compile_prompt(
"journey_system",
fallback=_SYSTEM_PROMPT_TEMPLATE,
variables={
"directory": directory,
"data_types": ", ".join(data_types),
"template_start": _TEMPLATE_START,
"template_end": _TEMPLATE_END,
"existing_section": existing_section,
},
)