Skip to content

feat: Graph tracking refactor — ManagedAgentGraph drives tracking for new runner shape#154

Draft
jsonbailey wants to merge 1 commit intojb/aic-2388/enrich-metricsfrom
jb/aic-2174/graph-tracking-refactor
Draft

feat: Graph tracking refactor — ManagedAgentGraph drives tracking for new runner shape#154
jsonbailey wants to merge 1 commit intojb/aic-2388/enrich-metricsfrom
jb/aic-2174/graph-tracking-refactor

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

Summary

Moves graph-level LaunchDarkly tracking from inside the runner implementations to the ManagedAgentGraph managed layer.

  • ManagedAgentGraph.run() now detects runner result type via isinstance:
    • AgentGraphRunnerResult (new shape): managed layer drives all graph-level tracking (path, duration, success/failure, total tokens) from result.metrics via the graph tracker
    • AgentGraphResult (legacy shape): tracking already occurred inside the runner; managed layer wraps the result without additional tracking
  • ManagedAgentGraph now accepts an optional graph: AgentGraphDefinition parameter used to create the graph tracker
  • LDAIClient.create_agent_graph() passes the resolved graph definition as graph=graph

Deliberate bridge pattern: The legacy detection branch exists because PR 11-openai and PR 11-langchain have not yet migrated their runners to return AgentGraphRunnerResult. Once both runners are migrated, the legacy AgentGraphResult branch becomes dead code and will be removed in PR 11-langchain's cleanup commit.

Depends on

Test plan

  • All existing tests pass (uv run pytest packages/sdk/server-ai/tests/)
  • New tests: test_managed_agent_graph_run_handles_new_shape, test_managed_agent_graph_new_shape_drives_tracking, test_managed_agent_graph_new_shape_no_graph_skips_tracking
  • Legacy tests continue to pass (AgentGraphResult path unchanged)

🤖 Generated with Claude Code

… new runner shape

ManagedAgentGraph.run() now detects the runner result type and dispatches
accordingly:
- AgentGraphRunnerResult (new shape): managed layer drives all graph-level
  tracking from result.metrics (path, duration, success/failure, total tokens)
  via the graph tracker. Node-level tracking from node_metrics will be wired
  once runners populate that field (PR 11-openai/langchain).
- AgentGraphResult (legacy shape): tracking already occurred inside the runner;
  managed layer wraps result without additional tracking.

ManagedAgentGraph now accepts an optional graph parameter (AgentGraphDefinition)
used to create the graph tracker. LDAIClient.create_agent_graph() passes the
resolved graph definition. This is a deliberate bridge pattern: the legacy
detection branch will be removed once both runners are migrated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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