edubruell / tidyllm

An tidy interface to large language model APIs for R
https://edubruell.github.io/tidyllm/
Other
9 stars 1 forks source link

Implement Experimental Tool Use with R Function Registration #8

Open edubruell opened 5 days ago

edubruell commented 5 days ago

Description:
Develop a tool use system, enabling the model to interact with user-defined R functions during conversations. This should include a general way to register tools in R, potentially using an llm_tools R6 class and a define_llm_tools() function that allows users to define tools (functions, descriptions, input schemas, etc.) and store them in an llm_tools object. The llm_tools objects should then be usable as an argument for api-functions. I would try to implement this only in claude() initially.

Possible Actions:

  1. Create an llm_tools R6 Class:

    • Design an R6 class, llm_tools, to store tool definitions, including function names, descriptions, and input schemas.
    • Implement methods for adding, updating, and removing tools.
  2. Develop the define_llm_tools() Function:

    • Create a function define_llm_tools() that takes R functions, descriptions, input schemas, and other relevant parameters to register tools in an llm_tools object.
    • Validate tool definitions to ensure proper formats for use with the Claude API.
  3. Integrate Tool Use with the claude() Function:

    • Allow claude() to accept an llm_tools object as an argument, passing the tool definitions to the API.
    • Modify the API request format to include tool descriptions and input schemas, as required by Claude's tool use guidelines.
  4. Implement Tool Execution and Handling:

    • Add mechanisms to extract tool input from Claude's tool use requests, execute the corresponding R function, and return the results to Claude.
    • Handle potential errors in tool execution and provide informative feedback.

Additional Considerations: