Coding Agent Example¶
Demonstrates the high-level CodingEnsemble.run() API for running a coding agent
directly in a project directory.
What It Does¶
- Accepts a project directory path as a command-line argument
- Auto-detects the project type (Java/Gradle, npm, Python, etc.)
- Assembles appropriate coding tools
- Runs a bug-fix task using the configured LLM
Code¶
ChatModel model = OpenAiChatModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.modelName("gpt-4o")
.build();
EnsembleOutput output = CodingEnsemble.run(
model,
Path.of("/path/to/project"),
CodingTask.fix("Find and fix any compilation errors"));
System.out.println(output.getRaw());
Running¶
export OPENAI_API_KEY=sk-...
./gradlew :agentensemble-examples:runCodingAgent --args="/path/to/your/project"
If no path argument is provided, the current directory is used.
Key Concepts¶
- Project detection:
ProjectDetectorscans the directory for build-file markers and returns aProjectContextwith language, build system, and source roots. - Tool assembly:
CodingAgent.builder()assembles the right tool set based on the detectedToolBackend(AUTO by default). - System prompt:
CodingSystemPromptgenerates a coding-specific agent background with workflow instructions and build/test commands.