Skip to content

Langextract observability: real agent events not captured β€” follow-ups after #1420Β #1421

@MervinPraison

Description

@MervinPraison

Context

Follow-up to #1412 / PR #1413. Post-merge local validation (pytest + real agentic Agent.start() + praisonai langextract render <yaml> + --observe langextract) surfaced a wiring gap that makes the langextract trace empty for almost all real-world agent flows. Fix posted in #1420.

Observed failure

$ praisonai langextract render simple.yaml -o render.html --no-open
...
Error: Trace was not rendered to render.html
# Python path β€” same gap
from praisonai.observability import LangextractSink, LangextractSinkConfig
from praisonaiagents.trace.protocol import TraceEmitter, set_default_emitter
from praisonaiagents import Agent

sink = LangextractSink(config=LangextractSinkConfig(output_path="trace.html"))
set_default_emitter(TraceEmitter(sink=sink, enabled=True))
Agent(instructions="...", name="w", llm="gpt-4o-mini").start("...")  # runs fine
sink.close()
# -> sink._events == []   # zero events captured, HTML not written

Root cause

LangextractSink is wired through get_default_emitter() / ActionEvent, but the core runtime emits rich lifecycle events exclusively via ContextTraceEmitter / ContextTraceSinkProtocol (praisonaiagents/trace/context_events.py). Grep of the whole core shows only two ActionEvent producers:

File Line Event
praisonaiagents/agent/router_agent.py 253 RouterAgent token usage (output)
praisonaiagents/agents/agents.py 2344 PlanningAgent plan_created

All agent_start, agent_end, tool_call_start, tool_call_end, llm_request, llm_response flow through the context emitter only (chat_mixin.py, tool_execution.py, unified_execution_mixin.py).

Same architectural gap affects LangfuseSink (_setup_langfuse_observability uses the identical pattern in cli/app.py).

Fix shipped in #1420 (wrapper-only)

  • _ContextToActionBridge adapter implementing ContextTraceSinkProtocol forwards ContextEvent β†’ ActionEvent.
  • LangextractSink.context_sink() exposes the bridge.
  • _setup_langextract_observability and langextract render install a ContextTraceEmitter(sink=sink.context_sink(), enabled=True) via set_context_emitter.
  • 3 regression tests; 19/19 unit tests pass.
  • Real agentic run now produces trace.html (3036 B) + trace.jsonl (1356 B).

Follow-ups (out of scope for #1420)

  1. chat_mixin.llm_response payload quality. The emitter gets response_content=str(final_response), which serialises the entire ChatCompletion object. The HTML final_output extraction shows this verbose repr instead of the actual message text. A small upstream change in chat_mixin.py to pass final_response.choices[0].message.content (with fallback) would dramatically improve the visualization. Touches core SDK, so left for a follow-up.
  2. Langfuse mirror fix. Apply the same ContextTraceSinkProtocol bridge pattern for LangfuseSink in _setup_langfuse_observability. Likely broken today for the same reason.
  3. praisonaiagents/tools/langextract_tools.py. Original Integration: Add langextract as a local visual trace layer (observability HTML viewer + CLI)Β #1412 plan listed a first-class LangExtractTool wrapping langextract.extract for agents to call. Not yet implemented.
  4. Incidental: agents_generator.py:1112 had import os inside a conditional that shadowed the module-level os, causing UnboundLocalError in _run_praisonai whenever acp/lsp were disabled (i.e. any default YAML run). Fixed in fix(langextract): bridge ContextTraceEmitter so real agent events produce a non-empty traceΒ #1420 as part of the blocker unblocker, but should be re-reviewed on its own.

Acceptance criteria for this tracking issue

References

@claude please pick this up once #1420 merges and implement follow-ups 1–4 per the AGENTS.md principles (protocol-driven, lazy imports, no core regressions, tests-first).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingclaudeAuto-trigger Claude analysisdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions