Skip to content

Phase 3: optional agent-core TraceEvent/CostUsage emission (additive, flag-gated)#24

Merged
Svaag merged 1 commit into
mainfrom
feat/agent-core-trace-emission
Jun 29, 2026
Merged

Phase 3: optional agent-core TraceEvent/CostUsage emission (additive, flag-gated)#24
Svaag merged 1 commit into
mainfrom
feat/agent-core-trace-emission

Conversation

@Svaag

@Svaag Svaag commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

Phase 3 of the Agent Runtime Framework rollout: emit standard agent-core observability
records from the engineering loop, alongside existing behavior. Higher fidelity than the
knowledge loop — engineering-loop state carries real token/USD cost in backend_results[].cost.

  • src/hyrule_engineering_loop/agent_core_trace.pyemit_loop_trace(state): one
    TraceEvent per llm_outputs / gate_results / backend_results item (backend events
    carry CostUsage), correlated by change_id as run_id.
  • trace.py — additive call at the top of write_loop_trace.
  • tests/test_agent_core_trace.py.

Safety / additive guarantees

  • No-op by default. Requires HYRULE_ENGINEERING_AGENT_CORE_TRACE truthy and the
    optional agent-core package. Verified: enabled()==False, emit_loop_trace→0.
  • agent-core is not a declared dependency — imported dynamically via importlib, so
    mypy --strict src and uv are unaffected and CI without it skips the new test
    (importorskip).
  • Best-effort: any emission error is swallowed; the loop is never affected.
  • Records append as JSON lines to HYRULE_ENGINEERING_AGENT_CORE_TRACE_PATH
    (default reports/agent-core-trace.jsonl).

Verification (local, agent-core installed)

  • ruff check src tests clean, mypy --strict src clean (33 files), full suite 196 passed
    (+2 new emitter tests).

Third in the series after agent-core (contracts) and knowledge PR #20.

🤖 Generated with Claude Code

…itive)

Flag-gated, best-effort emission of standard agent-core TraceEvents (incl. CostUsage from backend_results) at the loop_trace write point, ALONGSIDE existing behavior. No-op unless HYRULE_ENGINEERING_AGENT_CORE_TRACE is truthy AND the optional agent-core package is installed (NOT a declared dependency; agent_core imported dynamically via importlib so 'mypy --strict src' and uv are unaffected, and CI without it skips the new test).

Files: src/hyrule_engineering_loop/agent_core_trace.py (emit_loop_trace); trace.py additive call in write_loop_trace; tests/test_agent_core_trace.py. ruff + mypy --strict clean; full suite 196 passed; off by default (no behavior change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Svaag Svaag merged commit 711d876 into main Jun 29, 2026
4 checks passed
@Svaag Svaag deleted the feat/agent-core-trace-emission branch June 29, 2026 02:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3112437158

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def write_loop_trace(state: GraphState) -> str | None:
"""Write ``loop_trace.json`` beside the NOC handoff when configured."""
emit_loop_trace(state)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate agent-core events emitted from repeated trace writes

When HYRULE_ENGINEERING_AGENT_CORE_TRACE is enabled and memory_dir is set, write_loop_trace is called once in package_pr/human_signoff and again from reflection (the graph routes both terminal nodes to reflection). Because this line emits the entire accumulated state on every call and the sink appends, the same llm_outputs/gate_results/backend_results become duplicate agent-core records, so backend CostUsage will be counted twice for runs with memory enabled. Gate this to a final write or emit only new records.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant