DEV Community

Cover image for Designing .NET CLI Output for AI Agents
Rushui Guan
Rushui Guan

Posted on Edited on

Designing .NET CLI Output for AI Agents

It’s been about a year since we released Albatross.CommandLine v8. We’ve used it in production across a number of projects, and reusable options have become one of the features we rely on most. Along the way, we added Albatross.CommandLine.CodeAnalysis to help developers catch issues at compile time. We also updated the source generator packaging so consuming projects automatically reference it as a development dependency.

With the release of System.CommandLine v3, we’ve released Albatross.CommandLine v9, targeting .NET 10 and .NET Standard 2.1. In my previous article, I wrote about how a command takes an input like --instrument AAPL and passes an InstrumentSummary to its handler. Much of the work in v9 focuses on the other end of that interaction. What should the command print when the caller is an AI agent?

Why CLI output matters

As we use AI agents for more of our development work, verifying their changes becomes increasingly important. We also rely on agents to write and run integration tests, including tests that span multiple services. How do we make sure those tests exercise the behavior we care about?

Our systems use a service-oriented architecture, and we rely heavily on CLIs to test them. A CLI gives the agent a defined set of operations it can use to build a test. It can run one command, inspect the result, and use a value from that result in the next command. For that to work reliably, the agent needs to know what to expect from each command’s output.

Two kinds of results

The first change in v9 was to remove default console logging. If a command prints a price as JSON, I want to be able to pipe it straight into ConvertFrom-Json. One log message on standard output is enough to break that pipeline.

The second change was to introduce Albatross.CommandLine.Outputs. For a command that returns data, the output is straightforward. A price lookup can serialize the quote to JSON and print it directly.

An update is a little different. It might have no data to return, but the caller still needs to know how the operation went. The command can report that outcome using a CommandOutput envelope.

public record class CommandOutput {
    public required string Command { get; init; }
    public string? Message { get; set; }
    public IReadOnlyCollection<ErrorOutput>? Errors { get; set; }
    public required int ExitCode { get; init; }
    public string? LogFolder { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

Every envelope identifies the command and reports its exit code. When an operation fails, the agent can inspect Errors and, if it needs more detail, find the logs through LogFolder.

A well designed Cli provides guardrails and reduce hallucinations

A CLI gives AI agents guardrails by defining the operations they can perform and the inputs each operation accepts. Normalized output reduces guesswork and helps prevent hallucinations by giving agents a predictable way to interpret each result. An agent can use one command to make a change and another to check its effect, grounding the test in behavior it can actually observe. In our experience, this approach has worked well with agents within our large muti-domain systems.

v9 release notes · Albatross.CommandLine documentation

Top comments (0)