Skip to main content
There are two main optons to integrate Fast Agentic Search (FAS) into your agentic coding system.
  1. Call FAS as a preliminary subagent that collects context for the central agent.
  2. Allow the central agent to call FAS as a file exploration tool at any point in its loop.
In both, it’s important to format FAS results in a way the central agent can make use of it.

Subagent Formatting

In this pattern, you run FAS before the main agent loop starts. This is useful for “one-shot” tasks where the user’s intent is clearly to find or modify code (e.g., “Fix the bug in the auth service”). By pre-filling the context window with relevant file locations, you save the main agent from having to spend a turn asking for them.

Workflow

  1. Receive User Query: “How is the user session duration calculated?”
  2. Run FAS: Call repo.search() immediately with the user’s query.
  3. Hydrate Context: Append the search results to the system prompt or user message.
  4. Run Main Agent: The agent now has the answer in its context immediately.
import { Relace } from '@relace-ai/relace';

const client = new Relace({ apiKey: 'YOUR_API_KEY' });
const repoId = 'YOUR_REPO_ID';

// 1. Receive query
const userQuery = 'How is the user session duration calculated?';

// 2. Run FAS in parallel or before the main LLM call
const searchResults = await client.repo.search({
  repoId: repoId,
  query: userQuery,
});

// 3. Inject into context
const contextWithSearch = `
  User Query: ${userQuery}

  [System Note: Automated Search Results]
  Fast Agentic Search found the following relevant code:
  ${formatResultsForLLM(searchResults)}
`;

// 4. Call Main Agent
const response = await llm.generate(contextWithSearch);
This approach reduces latency for the user, as they don’t have to wait for the agent to “think” about searching—the search happens automatically.

Tool Approach

In this pattern, you expose FAS as a tool that your main agent can choose to invoke. This gives the agent autonomy to decide when it needs to search the codebase. This is ideal for multi-turn conversations where the agent might need to look up information dynamically based on intermediate reasoning.

Tool Definition

Define a tool (e.g., search_codebase) that wraps the FAS API.
// Example tool definition for your agent framework (e.g., LangChain, Vercel AI SDK)
const searchCodebaseTool = {
  name: 'search_codebase',
  description: 'Search the codebase for relevant files using natural language.',
  parameters: {
    type: 'object',
    properties: {
      query: {
        type: 'string',
        description:
          'A natural language query describing what you are looking for.',
      },
    },
    required: ['query'],
  },
  execute: async ({ query }) => {
    const results = await client.repo.search(repoId, {
      query: query,
    });

    // Format the output for the model
    return formatResultsForLLM(results);
  },
};

Merging the Output

When the tool returns, you should format the results into a concise string that the model can digest. This effectively simulates the report_back behavior of the search agent.
import { relace } from '@relace-ai/relace';

async function formatResultsForLLM(
  searchStream: AsyncIterable<relace.RepoAgentResponse>
): Promise<string> {
  let files: [string, [number, number][]][] = [];

  // Consume the SSE stream
  for await (const event of searchStream) {
    // Look for the report_back tool event which contains the final results
    if (event.event === 'tool' && event.data?.name === 'report_back') {
      files = Object.entries(event.data.files);
    }
  }

  // Format the output
  if (!files || files.length === 0) {
    return 'No relevant files found.';
  }

  return (
    `Found ${files.length} relevant files:\n` +
    files
      .map(([filename, ranges]) => {
        const rangeStr = ranges
          .map(([start, end]) =>
            start === end ? `line ${start}` : `lines ${start}-${end}`
          )
          .join(', ');
        return `- ${filename} (${rangeStr})`;
      })
      .join('\n')
  );
}
Example output:
Found 6 relevant files:
- package.json (lines 1-50)
- src/App.tsx (lines 1-15)
- src/main.tsx (lines 1-15)
- src/components/theme-toggle.tsx (lines 1-35)
- index.html (lines 1-15)
- src/hooks/use-theme.tsx (lines 1-30)