We stopped feeding our agent context and made it search for context instead - it removed a large part of our agent errors

Reddit r/AI_Agents Tools

Summary

The author shares that replacing pre-injected context with a search tool the agent calls on-demand, backed by structured documents in OpenSearch, greatly reduced agent errors and improved traceability.

tl;dr Don't inject custom context basis user query/RAG/etc. into prompt, make agent search it with a tool with params (query, filter, search_type, temporal, limit). It was the single biggest lever to bring control on using the agent.. I build AI agents at my company, and initially, our context layer was obsidian stlye skills markdown files folders, cross-links. We would initially do vector search / RAG and inject the context alongside prompts. We used to see repetitive challenges there and we went down rabbit hole trying to fix it.. What kept breaking: Context poisoning / digression. Once we were past ~50 markdown files, the agent would wander between docs and pick up instructions that had nothing to do with the task. We tried building explicit navigation paths and interlinking everything, but it didn't help much. No source proof. As the knowledge base grew, we couldn't reliably say which piece of context drove a given action. Users won't trust an agent that can't show its work. What actually worked for us: Structured docs instead of markdown. We moved context into JSON / structured documents. Agents navigate way better when things look like code. We had about 10-12 document types and then each type had 5-8 fields within them Make the agent search, don't spoon-feed it. Instead of pre-injecting context, we gave it meta-info about what context exists and made it responsible for searching and discovering the right pieces (tool-based search capability for the agent rather than us running RAG/prompt expansion upstream). For search, we created a tool search_resources that would run queries on the opensearch index in which the structured docs were stored - the tool we created had 5 parameters: * query - Select the query it wants to run * filter - Filter by specific type of documents * search_type - Define search type (semantic / syntactic) * temporal - Add temporal True/False if your data has time based staleness * limit - number of responses it receives in return If you're doing something similar, what's your experience been? What else is working great for you?
Original Article

Similar Articles