Skip to content

Conversation

@erikgaas
Copy link
Contributor

Enhances @llmtool to auto-detect __for_llm__ classmethod on the first param's class.

Adds helper functions:

  • params(f, exclude) - get parameter annotations
  • extract_args(names, a, kw) - extract args from positional/kwargs
  • call_via(via, method_name, a, kw, via_keys) - create object via factory and call method
  • merge_hints(via, f) - combine type hints from two functions

Usage:

class Page:
    @classmethod
    def __for_llm__(cls, tab_id: int) -> Page: ...

@llmtool
def read(self:Page) -> str: ...

One decorator that patches the method AND creates a tool version.

@erikgaas erikgaas changed the base branch from master to main January 23, 2026 18:45
@erikgaas erikgaas added the enhancement New feature or request label Jan 23, 2026
from .basics import anno_ret
return {**params(via, exclude=exclude), **params(f, exclude=exclude), 'return': anno_ret(f) or str}

def llmtool(f=None, *, via=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that this should be in tools.py, but im guessing there is an issue with that so it was put here so it was loaded before any other code.

@erikgaas erikgaas requested a review from jph00 January 23, 2026 18:47
@jph00
Copy link
Contributor

jph00 commented Jan 27, 2026

Yeah this has gotten big enough now that it should be removed from imports and put in a proper nb, with explanations/examples/etc. Maybe a new section in xtras?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants