Add agent output mode (NXF_AGENT_MODE)#6782
Conversation
✅ Deploy Preview for nextflow-docs-staging canceled.
|
903a1a0 to
bc04da9
Compare
|
Interesting, but does it still need ansi escape capabilities? |
|
No, agent mode doesn't need ANSI escape capabilities. The implementation explicitly disables ANSI output. The feature was intentionally designed this way. When NXF_AGENT=true:
|
|
Nice! |
ewels
left a comment
There was a problem hiding this comment.
Very nice!
Haven't tested but a skim of the code on my phone looks sensible / as I'd expect 👍🏻
|
is the output format complete for this? |
modules/nextflow/src/main/groovy/nextflow/trace/AgentLogObserver.groovy
Outdated
Show resolved
Hide resolved
|
This works better with ansi-mode false |
edd3bc4 to
9445df3
Compare
Tests for AI agent-friendly output mode via env vars. All tests marked @PendingFeature until implementation. Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Add AI agent-friendly output mode triggered by env vars: - NXF_AGENT=true - AGENT=true - CLAUDECODE=true When enabled, outputs minimal structured format: - [PIPELINE] name version | profile=X - [WORKDIR] path - [WARN] deduplicated warnings - [ERROR] with exit/cmd/stderr/workdir context - [SUCCESS|FAILED] summary Achieves 98-100% token savings for AI context windows. Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
- agent-output.nf: Tests successful workflow in agent mode - agent-output-error.nf: Tests error output format in agent mode - Validates [PIPELINE], [WORKDIR], [SUCCESS/FAILED] format - Verifies banner suppression and error context (exit code, workdir) Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Co-authored-by: Ben Sherman <bentshermann@gmail.com> Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Co-authored-by: Ben Sherman <bentshermann@gmail.com> Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Only one observer is ever active. Use instanceof for ANSI-specific features (appendSticky, started/stopped checks). Co-authored-by: Ben Sherman <bentshermann@gmail.com> Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Task hashes and submission lines flow through ConsoleAppender instead of being captured and suppressed. Co-authored-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
9445df3 to
627659b
Compare
…t mode AgentLogObserver.println wrote to System.out but integration tests capture stderr. Also enable CaptureAppender in agent mode so log-level warnings/errors are forwarded to the observer. Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
printConsole was routing view operator output through logObserver.appendInfo() which suppresses most messages in agent mode. Only AnsiLogObserver needs to capture console output for rendering. Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
Remove the LogObserver interface abstraction and reference each observer by its concrete type. Session now holds separate ansiLogObserver and agentLogObserver fields so neither mode pollutes the other. Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Add LogObserver interface as common abstraction for AnsiLogObserver and AgentLogObserver. Session now holds a single logObserver field instead of two concrete fields. Move AgentLogObserver creation to DefaultObserverFactory to match AnsiLogObserver pattern. Print process submissions in agent mode. Rename NXF_AGENT env var to NXF_AGENT_MODE. Add env var documentation. Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
|
Update on output streams: After testing, the agent mode structured output ( This means both structured agent output and workflow output (e.g. from the We can revisit this in the future if separating structured output (stderr) from workflow output (stdout) becomes necessary — that would require changes to the |
Summary
Add AI agent-friendly output mode for Nextflow, triggered by environment variables:
NXF_AGENT_MODE=trueAGENT=1CLAUDECODE=1When enabled, Nextflow outputs a minimal format optimized for AI agent context windows.
Inspired by Bun's test agent mode
Output Format
Key Features
Architecture
LogObserverinterface — common abstraction forAnsiLogObserverandAgentLogObserver, allowingSessionandLoggerHelperto work through a singlelogObserverfieldAgentLogObserver—TraceObserverV2+LogObserverimplementation for minimal outputDefaultObserverFactory— creates both ANSI and agent observers using the same patternSysEnv.isAgentMode()— detects agent mode via env varsToken Savings
Experiments show 98-100% token savings while preserving all diagnostic information:
Tests
AgentLogObserverTest— output formatting testsAnsiLogObserverTest— ANSI observer tests (unchanged behavior)SysEnvTest—isAgentMode()detection tests