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:- The user asks a question about a codebase.
- The LLM decides which tool to call and with what arguments.
- Your runtime executes the call against the CodeAlive Tool API (or through MCP) and appends the result to the conversation.
- Steps 2–3 repeat until the LLM has enough evidence, then it writes the final answer.
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:| Tool | Role in the loop |
|---|---|
get_data_sources | Discover repository and workspace names. Call once at session start. |
get_repository_ontology | Orient: high-level map of one repository before focused search. |
get_file_tree | Orient: bounded directory structure with summaries. |
semantic_search | Locate by meaning: default first tool for behaviour and architecture questions. |
grep_search | Locate by text: exact names, literals, error strings, acronyms, exhaustive sweeps. |
fetch_artifacts | Read: preferred reader for known artifact identifiers. |
get_artifact_relationships | Traverse: callers, callees, inheritance, references of a known artifact. |
read_file | Read: fallback for exact paths without an artifact identifier; bound with start_line/end_line. |
get_artifact_query_schema | Analytics: the ArtifactQuery DSL catalog. |
query_artifact_metadata | Analytics: repository-level metrics (languages, lines, complexity, public API surface). |
chat | Delegate: 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. |
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?”:Discover data sources
agent-framework as a ready repository — its name goes into every following call.Search by meaning
CodeAlive-AI/agent-framework::src/executor.py::TaskExecutor.run — a method artifact with a relevance score and a one-line description.Read the core
Find the entry point
Scheduler.tick in src/scheduler.py — the upstream trigger that drains the queue.Practical notes
- Rate of tool calls. Search tools are billed per call (see
x-codealive-billingin 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 — thetryhint is written so an LLM can repair the call and retry. - Stateless
chat. If you do exposechat, remember every call is independent: prior findings and identifiers must be repeated insidequestion.
Related resources
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