Implementation:3641397194 wq Gpt6 Astra runAgent
| Knowledge Sources | |
|---|---|
| Domains | AI_Agents, Tool_Use, Security |
| Last Updated | 2026-10-26 12:00 GMT |
Overview
Concrete tool for running an autonomous AI agent loop that selects and executes security tools with scope enforcement, provided by the ColdBrew Zero toolbox library.
Description
The runAgent function implements the ReAct (Reasoning + Acting) loop for the original toolbox. Each round, the AI model receives the goal, accumulated observations, and tool catalog, then returns a JSON decision: either a tool call (`{"tool":"name","arguments":{...}}`) or completion (`{"done":true,"summary":"..."}`). The host validates the decision's scope via scopeCheck, executes the tool via engine.execute, and appends the result to history.
The loop enforces:
- Preview rejection: throws if `adapter.status().mode === 'preview'` — real API required.
- Round limit: `maxRounds` clamped to [1, 16], default 8.
- Untrusted output: the constraints string instructs the model to treat all tool output as data, never instructions.
- Observation truncation: each result is stringified and sliced to 12000 chars.
- Derived file tracking: files created by `patch_bytes` are added to the `derived` set.
- Evidence-based completion: `status` is `completed` only if all calls succeeded.
The responseText helper extracts text from three response shapes. The decision helper strips code fences and parses JSON. The scopeCheck function validates arguments against the declared target.
Usage
- Toolbox agent loop: the main entry point for autonomous security analysis.
- Web recon: goal describes a web target; the agent chains resolve_host → scan_ports → inspect_http → crawl_site → find_paths → check_web.
- Binary analysis: goal describes a binary file; the agent chains analyze_binary → search_bytes → patch_bytes → diff_files, optionally with IDA tools.
- IDA integration: pass `idaUrl` to enable `ida_connect` and `ida_call` tools.
Code Reference
Source Location
- Repository: ColdBrew Zero
- File: desktop/src/lib/toolbox/agent.js
Signature
async function runAgent(engine, adapter, input, ctx) -> {
status: 'completed' | 'partial',
summary: string,
calls: Array<{ tool, arguments, result?, error? }>,
rounds: number,
evidenceBased?: boolean
}
function responseText(response) -> string
function decision(text) -> { tool?, arguments?, done?, summary? }
function scopeCheck(name, args, target, derived, idaUrl) -> void // throws on scope escape
Import
const { runAgent, responseText, decision, scopeCheck } = require('./toolbox/agent');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| engine | ToolboxEngine | Yes | Tool execution engine |
| adapter | RelayAdapter | Yes | Relay adapter (must not be in preview mode) |
| input.modelId | string | Yes | Relay model ID |
| input.goal | string | No | Task goal (default: "分析 <target> 并输出实际结果") |
| input.target | string | Yes | Declared target URL or file path |
| input.idaUrl | string | No | IDA MCP server URL |
| input.maxRounds | number | No | Max rounds (default 8, clamped to [1,16]) |
| ctx.signal | AbortSignal | No | Cancellation signal |
| ctx.emit | function | No /// Event emitter for round/call state updates |
Outputs
| Name | Type | Description |
|---|---|---|
| status | string | 'completed' (all calls succeeded) or 'partial' (some failed or round limit) |
| summary | string | AI-provided summary (completed) or round-limit message (partial) |
| calls | Array | Per-call record: { tool, arguments, result?, error? } |
| rounds | number | Number of rounds executed |
| evidenceBased | boolean | True if any call has a non-error result |
Usage Examples
Web Reconnaissance
const { runAgent } = require('./toolbox/agent');
const { ToolboxEngine } = require('./toolbox/engine');
const { RelayAdapter } = require('./relay-adapter');
const engine = new ToolboxEngine({ workspace: '/tmp/toolbox' });
const adapter = new RelayAdapter({
mode: 'openai',
baseUrl: 'https://api.coldcoffeeai.com/v1',
authToken: 'sk-key'
});
const result = await runAgent(engine, adapter, {
modelId: 'gpt-6-astra',
goal: 'Perform web reconnaissance on the target and report findings',
target: 'https://example.com',
maxRounds: 10
}, { signal: AbortSignal.timeout(120000) });
console.log(`Status: ${result.status}`);
console.log(`Rounds: ${result.rounds}`);
console.log(`Calls: ${result.calls.length}`);
for (const call of result.calls) {
console.log(` ${call.tool}: ${call.error ? 'ERROR: ' + call.error : 'OK'}`);
}
Binary Analysis with IDA
const { runAgent } = require('./toolbox/agent');
const { ToolboxEngine } = require('./toolbox/engine');
const engine = new ToolboxEngine({ workspace: '/tmp/toolbox' });
engine.importSample('/tmp/suspicious.exe');
const result = await runAgent(engine, adapter, {
modelId: 'gpt-6-astra',
goal: 'Analyze the binary, search for crypto constants, and patch the license check',
target: 'samples/<sha256prefix>-suspicious.exe',
idaUrl: 'http://localhost:13337/mcp',
maxRounds: 12
}, {});
// The agent may chain: analyze_binary → search_bytes → ida_connect → ida_call → patch_bytes → diff_files
Scope Check Directly
const { scopeCheck } = require('./toolbox/agent');
// Valid: URL matches target origin
scopeCheck('inspect_http', { url: 'https://example.com/path' }, 'https://example.com', new Set());
// OK
// Invalid: URL escapes target origin
try {
scopeCheck('inspect_http', { url: 'https://evil.com' }, 'https://example.com', new Set());
} catch (error) {
console.log(error.message); // 'AI 地址超出本次目标'
}
// Valid: derived file (created by patch_bytes earlier)
const derived = new Set(['/tmp/toolbox/patched/uuid-sample.exe']);
scopeCheck('diff_files',
{ file: 'samples/sha-sample.exe', other: 'patched/uuid-sample.exe' },
'samples/sha-sample.exe', derived);
// OK — 'other' is in derived set
Related Pages
Implements Principle
- Principle:3641397194_wq_Gpt6_Astra_Agent_Tool_Loop
- Principle:3641397194_wq_Gpt6_Astra_Scope_Enforcement