-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[fix] Make models stateless #3140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
def determine_tools_for_model(self, tools: List[Callable]) -> None: | ||
if self._tools_for_model is None: | ||
self._tools_for_model = [] | ||
self._functions_for_model = {} | ||
|
||
for tool in tools: | ||
try: | ||
function_name = tool.__name__ | ||
if function_name not in self._functions_for_model: | ||
func = Function.from_callable(tool, strict=True) # type: ignore | ||
func.strict = True | ||
self._functions_for_model[func.name] = func | ||
self._tools_for_model.append({"type": "function", "function": func.to_dict()}) | ||
log_debug(f"Added function {func.name}") | ||
except Exception as e: | ||
log_warning(f"Could not add function {tool}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still want the logic to run when self._tools_for_model
already has tools, right?
or is it cleaned on exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else can we clarify what the early exit is about? it's a bit obscure rn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once it is populated we don't need it to run again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It saves on processing time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working fine!
tools=self._tools_for_model, | ||
functions=self._functions_for_model, | ||
tool_choice=self.tool_choice, | ||
tool_call_limit=self.tool_call_limit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a general limit could be defined in the Model and be independent of the agent runs. Would be nice DX to set defaults when reusing a model.
model = OpenAIChat(..., tool_call_limit=5)
agent.run(..., tool_call_limit=10) # raises with InvalidLimit (or we use the min)
Not blocking, just an idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good idea!
Summary
Remove state like
response_format
andtools
from model state to avoid issues where models are shared between teams/agents.Fixes #3095
Type of change
Checklist
./scripts/format.sh
and./scripts/validate.sh
)Additional Notes
Add any important context (deployment instructions, screenshots, security considerations, etc.)