Overview

Autonomous AI agents can plan multi-step tasks, use tools, and deliver structured results without constant human supervision. With Cognipeer, you get a deterministic runtime that keeps you in full control — no black-box graphs, just a transparent message-driven loop.

This use case walks you through building a research assistant agent that can search, analyse, and synthesise information using the Cognipeer ecosystem.

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 provides the deterministic runtime that drives agent reasoning. It handles the core loop: resolve state → summarise context → call LLM → execute tools.

Agent Server exposes your agent as a production REST API with streaming, auth, and storage.

Chat UI gives users a conversational interface to interact with the agent in real time.

1. Define Tools with Agent SDK

Start by creating the tools your agent will use. Each tool has a name, description, Zod schema, and an async function.

1import { createTool } from "@cognipeer/agent-sdk";
2import { z } from "zod";
3 
4const searchWeb = createTool({
5 name: "search_web",
6 description: "Search the web for information",
7 schema: z.object({
8 query: z.string().describe("Search query"),
9 }),
10 func: async ({ query }) => {
11 // Integrate with your preferred search API
12 const results = await fetch(`https://api.search.example/q=${query}`);
13 return results.json();
14 },
15});
16 
17const summarise = createTool({
18 name: "summarise",
19 description: "Summarise a piece of text",
20 schema: z.object({
21 text: z.string().describe("Text to summarise"),
22 maxLength: z.number().optional().describe("Max summary length"),
23 }),
24 func: async ({ text, maxLength }) => {
25 return { summary: text.slice(0, maxLength || 500) + "..." };
26 },
27});

2. Create the Agent

Create a smart agent with planning enabled. The agent will use a TODO list to break down complex tasks into steps.

1import { createSmartAgent, fromLangchainModel } from "@cognipeer/agent-sdk";
2import { ChatOpenAI } from "@langchain/openai";
3 
4const model = fromLangchainModel(new ChatOpenAI({
5 model: "gpt-4o",
6 apiKey: process.env.OPENAI_API_KEY,
7}));
8 
9const researchAgent = createSmartAgent({
10 name: "ResearchAssistant",
11 model,
12 tools: [searchWeb, summarise],
13 systemPrompt: "You are a research assistant. Break down complex research questions into steps, search for information, and provide synthesised answers.",
14 useTodoList: true,
15 limits: { maxToolCalls: 10, maxToken: 16000 },
16 summarisation: { enabled: true, threshold: 12000 },
17 tracing: { enabled: true },
18});

3. Serve with Agent Server

Register the agent and expose it as a REST API with streaming support, persistent storage, and auto-generated Swagger docs.

1import express from "express";
2import {
3 createAgentServer,
4 createPostgresProvider,
5 createExpressMiddleware,
6} from "@cognipeer/agent-server";
7 
8const storage = createPostgresProvider({
9 connectionString: process.env.DATABASE_URL!,
10});
11 
12const server = createAgentServer({
13 basePath: "/api/agents",
14 storage,
15 swagger: { enabled: true, path: "/docs" },
16 auth: { enabled: true, type: "bearer" },
17});
18 
19// Register the agent
20server.registerSDKAgent("research-assistant", researchAgent, {
21 description: "A research assistant that searches and synthesises",
22 version: "1.0.0",
23});
24 
25const app = express();
26app.use(express.json());
27await storage.connect();
28app.use(createExpressMiddleware(server));
29app.listen(3000, () => console.log("Agent server on :3000"));

4. Connect Chat UI

Add a conversational interface with real-time streaming, tool visibility, and conversation history.

1import { Chat } from "@cognipeer/chat-ui";
2import "@cognipeer/chat-ui/styles.css";
3 
4function ResearchApp() {
5 return (
6 <div style={{ height: "100vh" }}>
7 <Chat
8 baseUrl="http://localhost:3000/api/agents"
9 agentId="research-assistant"
10 authorization="Bearer your-token"
11 theme="dark"
12 enableFileUpload={true}
13 />
14 </div>
15 );
16}

Result

You now have a complete autonomous research agent that:

- Plans complex tasks using a TODO list - Executes web searches and summarisation tools - Streams real-time responses to the user - Persists conversations in PostgreSQL - Traces every step for observability - Exposes interactive API docs at /docs

All recipesSuggest a change