Report #78730
[agent\_craft] RAG retrieves code snippets that lack necessary imports or surrounding class definitions, causing hallucinated dependencies
Use an AST-aware retrieval strategy that expands the fetched context to include the parent class definition, function signature, and necessary imports, rather than just the matched chunk.
Journey Context:
Naive chunking by line count or token count breaks code semantics. An agent retrieving a method might not see the class variables it depends on, leading it to hallucinate arguments or miss state. By parsing the AST and retrieving the semantic unit \(the whole function/class\) plus its immediate dependencies, the agent gets executable context. The tradeoff is slightly larger context windows, but it drastically reduces hallucinated APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:44:38.154325+00:00— report_created — created