inspecttools

Solveit tools for inspecting the symbol table and importing modules

This module provides LLM tools for Solveit to dynamically inspect source code, types, and module capabilities. Functions take string arguments (dotted symbol paths) rather than Python objects because LLM tool interfaces can only pass serializable values—not live Python references.


source

doimport

 doimport (mod:str)

Import a module into the caller’s global namespace

doimport lets the LLM dynamically import modules by name. Here we import fastcore.utils and verify it’s available.

doimport('fastcore.utils')
fastcore.__version__
'1.8.17'

source

resolve

 resolve (sym:str)

*Resolve a dotted symbol string to its Python object, with optional [n] indexing. Sets global _last to the resolved object for chaining. Pass "_last" to reference the result of the previous tool call.

Examples:

  • resolve("sympy.sets.sets.Interval") -> <class 'sympy.sets.sets.Interval'>
  • resolve("mylist[2]") -> third element of mylist*
Type Details
sym str Dotted symbol path, with optional [n] indexing, e.g. “module.attr.subattr[1]” or “_last” for previous result

resolve navigates dotted paths like "a.argfirst" to reach the actual Python object.

a = fastcore.utils.L(1)
resolve('a.argfirst')

It also sets _last for chaining. Since it’s used internally by all get* tools in this module, the tools all set _last too.

_last
<bound method L.argfirst of [1]>

It works on both objects and classes:

resolve('fastcore.utils.L.argfirst')
<function fastcore.foundation.L.argfirst(self, f, negate=False)>

source

symsrc

 symsrc (sym:str)

*Get the source code for a symbol.

Examples:

  • symsrc("sympy.sets.sets.Interval") -> source code of Interval class
  • symsrc("_last") -> source of object from previous tool call
  • For dispatchers or registries of callables: getnth("module.dispatcher.funcs", n) then symsrc("_last")*
Type Details
sym str Dotted symbol path or “_last” for previous result

symsrc retrieves the source code of any symbol by path—essential for letting the LLM understand how functions work.

print(symsrc('a.argfirst'))
    def argfirst(self, f, negate=False): 
        if negate: f = not_(f)
        return first(i for i,o in self.enumerate() if f(o))

source

gettype

 gettype (sym:str)

*Get the type of a symbol and set _last.

Examples:

  • gettype("sympy.sets.sets.Interval") -> <class 'type'>
  • gettype("_last") -> type of previous result*
Type Details
sym str Dotted symbol path or “_last” for previous result

gettype returns the type of a symbol—useful for the LLM to understand what kind of object it’s dealing with.

gettype('a.argfirst')
method

source

getdir

 getdir (sym:str)

Get dir() listing of a symbol’s attributes and set _last. E.g: getdir("sympy.Interval") -> ['__add__', '__and__', ...]

Type Details
sym str Dotted symbol path or “_last” for previous result

getdir lists all attributes of an object (i.e it calls dir(). Here we filter out private names to see the public API of an L list.

' '.join(o for o in getdir('a') if o[0]!='_')
'append argfirst argwhere attrgot clear concat copy copy count cycle enumerate extend filter groupby index insert itemgot items map map_dict map_first map_zip map_zipwith pop product range reduce remove renumerate reverse setattrs shuffle sort sorted split splitlines starmap sum unique val2idx zip zipwith'

source

getval

 getval (sym:str)

*Get repr of a symbol’s value and set _last.

Examples:

  • getval("sympy.sets.sets.Interval") -> <class 'sympy.sets.sets.Interval'>
  • getval("some_dict.keys") -> dict_keys([...])*
Type Details
sym str Dotted symbol path or “_last” for previous result

getval returns the repr() of a symbol’s value—handy for inspecting data without needing to execute arbitrary code.

getval('a')
'[1]'

source

getnth

 getnth (sym:str, n:int)

*Get the nth value from a dict (or any object with .values()). Sets _last so you can chain with symsrc("_last") etc.

Examples:

  • getnth("dispatcher.funcs", 12) -> 13th registered function
  • getnth("dispatcher.funcs", 0); symsrc("_last") -> source of first handler*
Type Details
sym str Dotted symbol path to a dict or object with .values()
n int Index into the values (0-based)

getnth extracts the nth value from a dict (or anything with .values()).

handlers = dict(int=lambda x: x*2, str=lambda x: x.upper(), list=lambda x: len(x))
getnth('handlers', 0)
<function __main__.<lambda>(x)>

Combined with _last, this lets the LLM drill into registries of handlers/dispatchers and then inspect their source.

symsrc('_last')
'handlers = dict(int=lambda x: x*2, str=lambda x: x.upper(), list=lambda x: len(x))\n'

source

inspect_tool_info

 inspect_tool_info ()
# inspect_tool_info()

Tools available from inspecttools: &[symsrc,gettype,getdir,doimport,getval,getnth]