Overview

Teams building custom agents usually hit the same wall: the agent works in a local test, but it is hard to compare runs, inspect tool sequences, and understand failures once multiple prompts, tools, and datasets are involved.

A practical pattern is to keep agent construction in Agent SDK while using Console as the place where traces are collected and reviewed.

When to reach for this recipe

If your team needs the capabilities described above and you'd rather build on proven primitives than wire one from scratch — this is the shape to start from.

Architecture

Agent SDK owns the runtime logic, tools, and control flow. Console SDK sends structured tracing data into Console, where product and platform teams can inspect sessions, thread-level workflows, latency, and token usage.

This creates a clean split: build agents where you need determinism, observe them where you need operational visibility.

1. Build The Agent In Agent SDK

Keep the runtime local to your application or service, but give each run a stable session and thread identity.

1import { createSmartAgent, createTool } from '@cognipeer/agent-sdk';
2 
3const agent = createSmartAgent({
4 name: 'PolicyReviewer',
5 model,
6 tools: [searchPolicyDocs, summarizeFindings],
7 systemPrompt: 'Review uploaded policies and produce structured findings.',
8 useTodoList: true,
9 tracing: { enabled: true },
10});
11 
12const sessionId = 'sess_' + Date.now();
13const threadId = 'thread_policy-review-2026-03';

2. Ingest Execution Data Into Console

After a run completes, send the session summary and important events into Console for later comparison and debugging.

1import { ConsoleClient } from '@cognipeer/console-sdk';
2 
3const client = new ConsoleClient({
4 apiKey: process.env.COGNIPEER_API_KEY!,
5 baseURL: 'https://console.example.com',
6});
7 
8await client.tracing.ingest({
9 sessionId,
10 threadId,
11 source: 'custom',
12 status: 'success',
13 startedAt,
14 endedAt: new Date().toISOString(),
15 durationMs: 1480,
16 agent: {
17 name: 'PolicyReviewer',
18 version: '0.3.0',
19 model: 'gpt-4o-mini',
20 },
21 summary: {
22 totalInputTokens: 1240,
23 totalOutputTokens: 420,
24 totalCachedInputTokens: 0,
25 totalBytesIn: 18000,
26 totalBytesOut: 6200,
27 eventCounts: {
28 ai_call: 2,
29 tool_call: 2,
30 },
31 },
32 events: traceEvents,
33 errors: [],
34});

3. Compare Agent Iterations By Thread

Thread correlation is useful when you are iterating on the same workflow across prompt versions, model changes, or tool updates.

1async function runReview(promptVersion: string, input: string) {
2 const startedAt = new Date().toISOString();
3 
4 const result = await agent.invoke({
5 messages: [{ role: 'user', content: input }],
6 });
7 
8 await client.tracing.ingest({
9 sessionId: sessionId + '-' + promptVersion,
10 threadId,
11 source: 'custom',
12 status: 'success',
13 startedAt,
14 endedAt: new Date().toISOString(),
15 durationMs: 1200,
16 agent: { name: 'PolicyReviewer', version: promptVersion, model: 'gpt-4o-mini' },
17 summary,
18 events: buildTraceEvents(result),
19 errors: [],
20 });
21}

Result

You get a development workflow that:

- Builds custom agents in Agent SDK without giving up observability - Captures tool calls, latency, and token usage in Console - Compares multiple agent versions through shared thread IDs - Speeds up debugging for prompt, model, and tool-chain changes

All recipesSuggest a change