Skip to content

feat: Adds a framework for using tools with LLMs#28

Open
s-alexey wants to merge 2 commits intocifrom
tools
Open

feat: Adds a framework for using tools with LLMs#28
s-alexey wants to merge 2 commits intocifrom
tools

Conversation

@s-alexey
Copy link
Contributor

@s-alexey s-alexey commented Feb 2, 2026

  • Core components for tool invocation and response modeling.
  • Helpers to convert Python functions to OpenAI and GenAI tool definitions.
  • A Tool actor for chat messages.

@s-alexey s-alexey requested a review from dolaameng February 2, 2026 15:53
@s-alexey s-alexey changed the title Adds a framework for using tools with LLMs feat: Adds a framework for using tools with LLMs Feb 2, 2026
Copy link
Contributor

@dolaameng dolaameng left a comment

Choose a reason for hiding this comment

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

Thank you @s-alexey ! I feel this is the right way for us to unify the function calls for different APIs. Left some comments so we can discuss and iterate.


fields[name] = (annotation, default)

DynamicModel = create_model(f"{func.__name__}", **fields)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if create_model will only work with pydantic model or dataclass, but not native class, unless we pass the parameter __config__=ConfigDict(arbitrary_types_allowed=True)?

Or we should explicitly warn against using parameters that are not validatable?

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 don't think we should support arbitrary types as at the end the llm will produce a json with arguments values. Added a custom exception for beter user experience



def function_to_genai_tool(
tool: Union[Callable, dict],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Shall we support the dict with a function key as well like {"type": "function", "function": {...}}, e.g., by

if "function" in tool:
  tool = tool["function"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is such a format used?

Copy link
Contributor

Choose a reason for hiding this comment

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

- Core components for tool invocation and response modeling.
- Helpers to convert Python functions to OpenAI and GenAI tool definitions.
- A `Tool` actor for chat messages.
Copy link
Contributor

@dolaameng dolaameng left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!



def function_to_genai_tool(
tool: Union[Callable, dict],
Copy link
Contributor

Choose a reason for hiding this comment

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

describe_tools,
invoke_tool,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add a test case for code like

from pydantic import BaseModel

# Pydantic or dataclass
class User(BaseModel):
    name: str
    age: int

def add_user(user: User):
    """Adds a new user to the database."""
    pass

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants