Skip to content

agent: consolidate context implementations in-place (alternative to P…#823

Draft
wolo-lab wants to merge 1 commit into
mainfrom
wolo/context_unif_v2_pr1_move_alt
Draft

agent: consolidate context implementations in-place (alternative to P…#823
wolo-lab wants to merge 1 commit into
mainfrom
wolo/context_unif_v2_pr1_move_alt

Conversation

@wolo-lab
Copy link
Copy Markdown

…R #1)

Same goal as wolo/context_unif_v2_pr1_move (eliminate the 3 pairs of duplicate context impls + the duplicate internalArtifacts helper), opposite execution: keeps existing implementations in agent/agent.go instead of moving them to new files.

What's added to agent/agent.go (~146 lines):

  • internalArtifacts wrapper (delta-tracking for Save).
  • NewCallbackContext / NewCallbackContextWithDelta constructors.
  • artifacts field on callbackContext + updated Artifacts() to return the wrapper (bug fix: previously returned unwrapped Artifacts, so Save() in callbacks didn't record into EventActions.ArtifactDelta).
  • NewInvocationContext + InvocationContextParams.
  • readonlyContext struct + 8 methods + NewReadonlyContext.
  • InvocationOf helper (returns underlying InvocationContext from a NewReadonlyContext-produced ReadonlyContext).
  • runBeforeAgentCallbacks / runAfterAgentCallbacks switched from raw struct literal to newCallbackContextImpl (no behavioural change — the new bug fix takes effect either way).

What's removed:

  • internal/context/{invocation,callback,readonly}_context.go shrink to thin alias layers (var NewX = agent.NewX).
  • internal/context/context_test.go deleted (its TestWithContext sibling already exists in agent/agent_test.go; the other two tests can be re-added in agent/ if desired).
  • internal/toolinternal.internalArtifacts dropped (toolContext now relies on the embedded CallbackContext for Artifacts wrapping — eliminates double-wrapping bug).
  • util/instructionutil drops the icontext import; uses agent.InvocationOf instead of *icontext.ReadonlyContext type assertion.

Trade-off vs the canonical PR #1:

  • agent/agent.go grows from 521 to ~660 lines (mixing Agent + Run
    • Context impls + helpers in one file).
  • 7 files touched instead of 13; +168/-352 = -184 lines net, versus +489/-537 = -48 net for PR Bump the go_modules group across 1 directory with 2 updates #1. ~136 lines smaller diff.
  • No new files in agent/ (3 fewer in git status).

This branch exists for comparison; whichever direction we pick gets PRs #2 and #3 stacked on top.

Verified: go build ./...; go vet ./...; go test ./...; all pass.

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • Closes: #issue_number
  • Related: #issue_number

2. Or, if no issue exists, describe the change:

If applicable, please follow the issue templates to provide as much detail as
possible.

Problem:
A clear and concise description of what the problem is.

Solution:
A clear and concise description of what you want to happen and why you choose
this solution.

Testing Plan

Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed go test results.

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Add any other context or screenshots about the feature request here.

…#1)

Same goal as wolo/context_unif_v2_pr1_move (eliminate the 3 pairs of
duplicate context impls + the duplicate internalArtifacts helper),
opposite execution: keeps existing implementations in agent/agent.go
instead of moving them to new files.

What's added to agent/agent.go (~146 lines):
  * internalArtifacts wrapper (delta-tracking for Save).
  * NewCallbackContext / NewCallbackContextWithDelta constructors.
  * artifacts field on callbackContext + updated Artifacts() to return
    the wrapper (bug fix: previously returned unwrapped Artifacts, so
    Save() in callbacks didn't record into EventActions.ArtifactDelta).
  * NewInvocationContext + InvocationContextParams.
  * readonlyContext struct + 8 methods + NewReadonlyContext.
  * InvocationOf helper (returns underlying InvocationContext from
    a NewReadonlyContext-produced ReadonlyContext).
  * runBeforeAgentCallbacks / runAfterAgentCallbacks switched from
    raw struct literal to newCallbackContextImpl (no behavioural
    change — the new bug fix takes effect either way).

What's removed:
  * internal/context/{invocation,callback,readonly}_context.go shrink
    to thin alias layers (var NewX = agent.NewX).
  * internal/context/context_test.go deleted (its TestWithContext
    sibling already exists in agent/agent_test.go; the other two
    tests can be re-added in agent/ if desired).
  * internal/toolinternal.internalArtifacts dropped (toolContext now
    relies on the embedded CallbackContext for Artifacts wrapping —
    eliminates double-wrapping bug).
  * util/instructionutil drops the icontext import; uses
    agent.InvocationOf instead of *icontext.ReadonlyContext type
    assertion.

Trade-off vs the canonical PR #1:
  * agent/agent.go grows from 521 to ~660 lines (mixing Agent + Run
    + Context impls + helpers in one file).
  * 7 files touched instead of 13; +168/-352 = -184 lines net,
    versus +489/-537 = -48 net for PR #1. ~136 lines smaller diff.
  * No new files in agent/ (3 fewer in git status).

This branch exists for comparison; whichever direction we pick gets
PRs #2 and #3 stacked on top.

Verified: go build ./...; go vet ./...; go test ./...; all pass.
@wolo-lab wolo-lab force-pushed the wolo/context_unif_v2_pr1_move_alt branch from ed246a5 to ea4fbfa Compare May 12, 2026 22:15
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