fix: prevent panic when LLMAgent has no Model configured#280
fix: prevent panic when LLMAgent has no Model configured#280rakyll merged 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @apzuk3, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential panic in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to prevent a panic when an LLMAgent is used without a configured model by adding a lazy validation. While the intention is correct, the current implementation of the check prevents a valid use case where BeforeModelCallbacks (for example, to implement caching) could provide a response, making a model unnecessary. I've suggested moving the nil-check to be truly lazy—executing it just before the model is actually called. This ensures the original panic is fixed while preserving the flexibility of using model-less agents with callbacks.
Add nil check in Flow.callLLM() after BeforeModelCallbacks but before accessing Model.GenerateContent(). This prevents a nil pointer dereference panic when an llmagent is created without a Model configuration. The check is positioned after BeforeModelCallbacks to allow callbacks that return cached responses to short-circuit execution without requiring a Model. This provides a clear error message instead of a cryptic segmentation fault: 'agent %q has no Model configured; ensure Model is set in llmagent.Config' Preserves valid use cases: - Testing agent metadata/structure without running the agent - BeforeAgentCallbacks that short-circuit before agent execution - BeforeModelCallbacks that return cached responses Fixes panic: runtime error: invalid memory address or nil pointer dereference when sub-agents without Models were invoked.
|
Thank you! |
Add nil check in Flow.callLLM() after BeforeModelCallbacks but before accessing Model.GenerateContent(). This prevents a nil pointer dereference panic when an llmagent is created without a Model configuration. The check is positioned after BeforeModelCallbacks to allow callbacks that return cached responses to short-circuit execution without requiring a Model. This provides a clear error message instead of a cryptic segmentation fault: 'agent %q has no Model configured; ensure Model is set in llmagent.Config' Preserves valid use cases: - Testing agent metadata/structure without running the agent - BeforeAgentCallbacks that short-circuit before agent execution - BeforeModelCallbacks that return cached responses Fixes panic: runtime error: invalid memory address or nil pointer dereference when sub-agents without Models were invoked.
Fixes #279
Since there is a valid use-case to initiate without providing a model, it did not make sense to validate during initialization. Added a lazy validation.