Add --record flag to record AI API interactions#1091
Merged
dgageot merged 6 commits intodocker:mainfrom Dec 15, 2025
Merged
Conversation
dgageot
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a
--recordflag tocagent run,cagent exec, andcagent apicommands, enabling users to record AI API interactions to cassette files. These recordings can later be replayed using the existing--fakeflag for testing and demo purposes.Features
--recordflag forexeccommand: Record a single question/answer interaction--recordflag forruncommand: Record an interactive TUI sessioncagent run agent.yaml --record # Auto-generates cagent-recording-<timestamp>.yaml--recordflag forapicommand: Record API server interactionsAuto-generated filenames: When
--recordis used without a value, a timestamped filename is generated automaticallyMutual exclusivity:
--fakeand--recordflags are mutually exclusive on theapicommand (you can't replay and record at the same time)Implementation Details
StartRecordingProxyfunction inpkg/fake/proxy.gothat configures VCR in record modeAPIKeyHeaderUpdaterto inject real API keys during recordingsetupRecordingProxyhelper incmd/root/record.goto eliminate duplicationTesting
Added comprehensive tests:
pkg/fake/proxy_test.go):APIKeyHeaderUpdaterandTargetURLForHostfunctionscmd/root/record_test.go):setupRecordingProxyhelper functione2e/cagent_record_test.go):TestExec_Record_CreatesCassette- Verifies cassette creation with explicit pathTestExec_Record_AutoGeneratesFilename- Verifies auto-generated filenamesTestAPI_FakeAndRecord_MutuallyExclusive- Verifies flag mutual exclusivityFiles Changed
cmd/root/run.go--recordflag and integrationcmd/root/exec.go--recordflagcmd/root/api.go--recordflag with--fakemutual exclusivitycmd/root/record.gocmd/root/record_test.gopkg/fake/proxy.goStartRecordingProxyandAPIKeyHeaderUpdaterpkg/fake/proxy_test.goe2e/cagent_record_test.go--recordflage2e/proxy_test.goAPIKeyHeaderUpdater