CodeboltAgent
Use CodeboltAgent when you don't need to change any logic in the agentic loop. You provide instructions, call processMessage, and the framework handles everything — context assembly, LLM calls, tool execution, compaction, and error recovery.
If you need to customize the loop — add processors, swap modifiers, inject pre/post hooks — use the Processor Pattern instead.
Source: packages/agent/src/unified/agent/codeboltAgent.ts
Quick start
import codebolt from '@codebolt/codeboltjs';
import { CodeboltAgent } from '@codebolt/agent/unified';
import { FlatUserMessage } from '@codebolt/types/sdk';
const agent = new CodeboltAgent({
instructions: 'You are a helpful coding assistant.',
});
codebolt.onMessage(async (reqMessage: FlatUserMessage) => {
const result = await agent.processMessage(reqMessage);
if (!result.success) {
throw new Error(result.error ?? 'Agent failed');
}
return result.finalMessage;
});
processMessage
const result = await agent.processMessage(message);
const result = await agent.processMessage(message, context);
| Parameter | Type | Description |
|---|---|---|
message | string | FlatUserMessage | The user message. A plain string is auto-wrapped into a FlatUserMessage |
context | ProcessedMessage (optional) | Continue from a previous conversation state — skips initial prompt generation |
Return value
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the run completed without errors |
result | ProcessedMessage | null | The final conversation state |
context | ProcessedMessage | null | Same as result — pass to a follow-up call to continue |
finalMessage | string | undefined | The agent's final text response |
error | string | undefined | Error message (only when success is false) |
Continuing a conversation
const firstResult = await agent.processMessage(reqMessage);
const secondResult = await agent.processMessage(
'Continue from the previous result.',
firstResult.context,
);
Or create a new agent with the context:
const followUpAgent = new CodeboltAgent({
instructions: 'Continue the previous task.',
context: firstResult.context ?? undefined,
});
const secondResult = await followUpAgent.processMessage('What was the outcome?');
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
instructions | string | 'Based on User Message send reply' | System prompt |
enableLogging | boolean | true | Log execution events to console |
maxTurns | number | 25 | Maximum LLM turns before the agent throws |
allowedTools | string[] | all tools | Restrict available tools by name |
context | ProcessedMessage | — | Resume from a previous conversation |
loopDetectionService | LoopDetectionService | — | Detect and break infinite loops |
compaction | CompactionOrchestratorOptions | {} | Conversation compaction settings |
Need to customize the pipeline? See Processor Pattern.
What it does under the hood
Each turn:
- Compaction — compresses the conversation if it's getting long.
- Tool refresh — re-fetches available tools from MCP servers.
- LLM call — sends the prompt, gets back text or tool calls.
- Tool execution — runs any tool calls the LLM requested.
- Check — if the LLM produced a final answer, return. Otherwise, next turn.
If the LLM hits a token limit, the agent automatically tries reactive compaction and retries.
Default message modifiers
When you don't customize processors.messageModifiers, these run automatically:
ChatHistoryMessageModifier— prior thread historyEnvironmentContextModifier— date, platform, workspace pathDirectoryContextModifier— workspace file treeIdeContextModifier— active file, open files, cursor, selectionCoreSystemPromptModifier— yourinstructionsToolInjectionModifier— available tools from Codebolt + MCP serversAtFileProcessorModifier— resolves @file mentions
To customize the pipeline, see Processor Pattern.
createCodeboltAgent helper
Maps systemPrompt to instructions:
import { createCodeboltAgent } from '@codebolt/agent/unified';
const agent = createCodeboltAgent({
systemPrompt: 'You are a helpful assistant.',
maxTurns: 20,
});
See also
- Patterns Overview
- Processor Pattern — customizing the pipeline
- Level 1 — Framework — project layout and build
- Built-in Processors — all shipped processors