8000 [fix] Make models stateless by dirkbrnd · Pull Request #3140 · agno-agi/agno · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[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

Merged
merged 26 commits into from
May 12, 2025
Merged

[fix] Make models stateless #3140

merged 26 commits into from
May 12, 2025

Conversation

dirkbrnd
Copy link
Contributor
@dirkbrnd dirkbrnd commented May 9, 2025

Summary

Remove state like response_format and tools from model state to avoid issues where models are shared between teams/agents.

Fixes #3095

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

Checklist

  • Code complies with style guidelines
  • Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh)
  • Self-review completed
  • Documentation updated (comments, docstrings)
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable)
  • Tested in clean environment
  • Tests added/updated (if applicable)

Additional Notes

Add any important context (deployment instructions, screenshots, security considerations, etc.)

@dirkbrnd dirkbrnd requested a review from a team as a code owner May 9, 2025 14:01
Comment on lines +50 to +65
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}")
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@dirkbrnd dirkbrnd changed the title [Fix] Make models stateless [fix] Make models stateless May 12, 2025
Copy link
Contributor
@manuhortet manuhortet left a 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,
Copy link
Contributor

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.

Copy link
Contributor Author

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!

@dirkbrnd dirkbrnd merged commit d4307c6 into main May 12, 2025
3 checks passed
@dirkbrnd dirkbrnd deleted the fix/model-state branch May 12, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants
0