MCPcopy Create free account
hub / github.com/braintrustdata/bash-agent-evals / main

Function main

src/debug-agent.ts:20–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18type AgentKey = keyof typeof AGENTS;
19
20async function main() {
21 const args = process.argv.slice(2);
22
23 if (args.length < 2) {
24 console.log(chalk.bold('Usage: pnpm debug <agent> <question>'));
25 console.log();
26 console.log('Agents: bash, fs, sql, embedding, codemode');
27 console.log();
28 console.log('Example:');
29 console.log(' pnpm debug fs "which project has the most issues?"');
30 process.exit(1);
31 }
32
33 const [agentKey, ...questionParts] = args;
34 const question = questionParts.join(' ');
35
36 if (!(agentKey in AGENTS)) {
37 console.log(chalk.red(`Unknown agent: ${agentKey}`));
38 console.log(`Available: ${Object.keys(AGENTS).join(', ')}`);
39 process.exit(1);
40 }
41
42 const agent = AGENTS[agentKey as AgentKey];
43 console.log(agent.color.bold(`\n═══ ${agent.name} Agent Debug ═══\n`));
44 console.log(chalk.dim(`Question: ${question}\n`));
45
46 // Wrap in a Braintrust trace
47 await traced(
48 async (span) => {
49 span.log({ input: question, metadata: { agent: agentKey } });
50
51 const callbacks: StreamCallbacks = {
52 onText: (chunk) => {
53 process.stdout.write(chalk.white(chunk));
54 },
55 onToolCall: (toolName, args) => {
56 console.log(chalk.cyan(`\n🔧 TOOL CALL: ${toolName}`));
57 console.log(
58 chalk.cyan(` Args: ${JSON.stringify(args, null, 2).split('\n').join('\n ')}`),
59 );
60 },
61 onToolResult: (toolName, result) => {
62 const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
63 console.log(chalk.gray(`\n↪ RESULT (${toolName}):`));
64 console.log(chalk.gray(` ${preview.split('\n').join('\n ')}`));
65 console.log();
66 },
67 onProgress: () => {},
68 };
69
70 try {
71 const result = await agent.fn(question, callbacks);
72
73 console.log(agent.color.bold(`\n\n═══ Final Result ═══\n`));
74 console.log(result.answer || chalk.dim('(no text response)'));
75 console.log();
76 console.log(chalk.dim(`─────────────────────────────────`));
77 console.log(chalk.dim(`Latency: ${(result.latencyMs / 1000).toFixed(2)}s`));

Callers 1

debug-agent.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected