Skip to main content

Overview

CodeAlive’s own chat is powered by an internal research agent that runs an LLM loop over the same tools exposed publicly as the Tool API and the MCP server. This guide shows how to build a similar agent yourself: which tools to give it, how to instruct it, and what a complete research loop looks like. The system prompt below is an adapted, self-contained version of the strategy CodeAlive uses in production. Copy it as a starting point and tune it for your stack.

Architecture

A code research agent is a loop:
  1. The user asks a question about a codebase.
  2. The LLM decides which tool to call and with what arguments.
  3. Your runtime executes the call against the CodeAlive Tool API (or through MCP) and appends the result to the conversation.
  4. Steps 2–3 repeat until the LLM has enough evidence, then it writes the final answer.
Every Tool API operation is read-only and returns the same envelope: obj (structured JSON) and rendered (agent-friendly text). For an agent loop, request output_format: "agentic" and feed rendered straight into the model — it is compact and already carries follow-up hints.

Which tools to give the agent

Expose all eleven tools; each covers a distinct move in the research loop:
ToolRole in the loop
get_data_sourcesDiscover repository and workspace names. Call once at session start.
get_repository_ontologyOrient: high-level map of one repository before focused search.
get_file_treeOrient: bounded directory structure with summaries.
semantic_searchLocate by meaning: default first tool for behaviour and architecture questions.
grep_searchLocate by text: exact names, literals, error strings, acronyms, exhaustive sweeps.
fetch_artifactsRead: preferred reader for known artifact identifiers.
get_artifact_relationshipsTraverse: callers, callees, inheritance, references of a known artifact.
read_fileRead: fallback for exact paths without an artifact identifier; bound with start_line/end_line.
get_artifact_query_schemaAnalytics: the ArtifactQuery DSL catalog.
query_artifact_metadataAnalytics: repository-level metrics (languages, lines, complexity, public API surface).
chatDelegate: a full end-to-end answer from CodeAlive’s own agent. Use sparingly — it is the most expensive tool, and you are already running your own loop.
The generated API Reference documents parameters, request examples, and response shapes for each tool.

Example system prompt

This prompt distills the search strategy CodeAlive’s production agent uses. It assumes the eleven tools above are bound with their canonical names.
system-prompt.md
The production prompt additionally handles multi-turn conversation state, workspace-scale scoping (up to ~1,000 repositories per workspace), and structured research-completion checkpoints. Those concerns are specific to CodeAlive’s harness — start with the version above and add orchestration rules as your agent grows.

Worked example

A typical run for “How does task execution work in agent-framework?”:
1

Discover data sources

The response lists agent-framework as a ready repository — its name goes into every following call.
2

Search by meaning

Top hit: CodeAlive-AI/agent-framework::src/executor.py::TaskExecutor.run — a method artifact with a relevance score and a one-line description.
3

Read the core

The artifact content shows retry and telemetry wrappers — this is the mechanism core, but not the entry point.
4

Find the entry point

Incoming calls reveal Scheduler.tick in src/scheduler.py — the upstream trigger that drains the queue.
5

Answer with evidence

The agent now has the full flow — entry point (Scheduler.tick), mechanism core (TaskExecutor.run), and side effects — and answers with file paths and short snippets.

Practical notes

  • Rate of tool calls. Search tools are billed per call (see x-codealive-billing in the OpenAPI spec); read and traversal tools (fetch_artifacts, get_artifact_relationships, read_file, get_file_tree) are not. Structure the loop to search once and read many.
  • Repairable errors. Invalid arguments come back as HTTP 200 with obj.error = { code, message, retry, try } and a rendered <tool_error> block. Feed the error to the model — the try hint is written so an LLM can repair the call and retry.
  • Stateless chat. If you do expose chat, remember every call is independent: prior findings and identifiers must be repeated inside question.

API Reference

Parameters and response examples for every tool

Instructing Coding Agents

Make off-the-shelf agents prefer CodeAlive tools

MCP Overview

Use the same tools through MCP instead of raw HTTP

Semantic Search

How CodeAlive’s search works under the hood