Skip to content

Definition Lookup

chimera.tools.definition_lookup finds where functions, classes, methods, and variables are defined across a codebase. It uses Python’s ast module for Python files and regex patterns for other languages (JS, TS, Go, Rust, Java, Ruby, C, C++).

ClassDescription
DefinitionLookupToolAgent tool that wraps DefinitionFinder
DefinitionFinderCore search engine — walks the file tree and matches definitions
DefinitionResult dataclass with symbol, kind, file, line, and source
from chimera.tools.definition_lookup import DefinitionFinder
finder = DefinitionFinder(workdir="/my/project")
defs = finder.find("MyClass")
for d in defs:
print(f"{d.file}:{d.line} ({d.kind}) -- {d.source[:80]}")

DefinitionLookupTool is a BaseTool that agents can call during a ReAct loop:

from chimera.tools.definition_lookup import DefinitionLookupTool
tool = DefinitionLookupTool()
result = tool.execute({"symbol": "create_provider", "file_hint": "chimera/providers/factory.py"}, env=env)
print(result.output)
  • Python files: Parsed with ast for accurate function, class, method, and variable definitions.
  • Other languages: Matched with language-specific regex patterns covering JS/TS functions and classes, Go funcs and structs, Rust fn/struct/trait/enum, Java/C/C++ classes, and Ruby defs/modules.
  • Directories like .git, node_modules, __pycache__, and .venv are automatically skipped.

Pass file_hint to search a specific file first, improving relevance when you know approximately where a symbol lives:

defs = finder.find("handle_request", file_hint="src/server.py")
from chimera.tools.definition_lookup import DefinitionLookupTool, DefinitionFinder, Definition