Skip to content

feat: Add generation_kwargs to run methods of Agent #9616

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jdb78
Copy link

@jdb78 jdb78 commented Jul 16, 2025

Related Issues

Proposed Changes:

added a generation_kwargs parameter to Agent which are to be passed to LLM

How did you test it?

added generation_kwargs to unit test run

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@jdb78 jdb78 requested a review from a team as a code owner July 16, 2025 20:24
@jdb78 jdb78 requested review from sjrl and removed request for a team July 16, 2025 20:24
@CLAassistant
Copy link

CLAassistant commented Jul 16, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Jul 16, 2025
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
Comment on lines +241 to +242
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[Dict[str, Any]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since I know other work is being done on this run method in a separate feature branch let's go ahead and make generation_kwargs a keyword only arg.

Suggested change
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[Dict[str, Any]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
*,
generation_kwargs: Optional[Dict[str, Any]] = None,

Comment on lines +345 to +346
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[Dict[str, Any]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Suggested change
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[Dict[str, Any]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
*,
generation_kwargs: Optional[Dict[str, Any]] = None,

@@ -746,7 +746,7 @@ def test_run(self, weather_tool):
chat_generator = OpenAIChatGenerator(model="gpt-4o-mini")
agent = Agent(chat_generator=chat_generator, tools=[weather_tool], max_agent_steps=3)
agent.warm_up()
response = agent.run([ChatMessage.from_user("What is the weather in Berlin?")])
response = agent.run([ChatMessage.from_user("What is the weather in Berlin?")], generation_kwargs={"temperature": 0.0})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a new unit test instead that resuses chat_generator = MockChatGeneratorWithoutRunAsync() and chat_generator.run.assert_called_once_with(messages=..., tools=..., generation_kwargs=...) so we can check that the generation_kwargs are being properly propogated?

@sjrl
Copy link
Contributor

sjrl commented Jul 21, 2025

Hey @jdb78 to help with the CI I'd also recommend checking out how to run our code-quality checks here and to add a release note to this PR as described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support generation_kwargs for Agent
3 participants