-
Notifications
You must be signed in to change notification settings - Fork 265
fix(sdk): prevent duplicate usage_id error when registering LLMs #3378
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
Changes from all commits
a8a31ea
e727887
c5a48c9
497d439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -633,8 +633,18 @@ def _ensure_agent_ready(self) -> None: | |||||||||||||||
| self.llm_registry.subscribe(self._state.stats.register_llm) | ||||||||||||||||
| registered = set(self.llm_registry.list_usage_ids()) | ||||||||||||||||
| for llm in list(self.agent.get_all_llms()): | ||||||||||||||||
| if llm.usage_id not in registered: | ||||||||||||||||
| self.llm_registry.add(llm) | ||||||||||||||||
| if llm.usage_id in registered: | ||||||||||||||||
| # Skip duplicates but warn - this shouldn't happen if agent | ||||||||||||||||
| # was validated properly, but can occur with deserialized | ||||||||||||||||
| # agents that have the same usage_id on multiple LLMs | ||||||||||||||||
| logger.warning( | ||||||||||||||||
| f"Skipping duplicate LLM registration for usage_id " | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: This warning fires for every skipped duplicate, including same-config ones that Since the validator ensures that any duplicate reaching
Suggested change
|
||||||||||||||||
| f"'{llm.usage_id}' (model={llm.model}). Consider using " | ||||||||||||||||
| f"distinct usage_id values for each LLM." | ||||||||||||||||
| ) | ||||||||||||||||
| continue | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 Important: Skipping the duplicate here leaves that LLM instance disconnected from |
||||||||||||||||
| self.llm_registry.add(llm) | ||||||||||||||||
| registered.add(llm.usage_id) | ||||||||||||||||
|
|
||||||||||||||||
| self._agent_ready = True | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
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.
🟡 Suggestion:
model_dump()in default Python mode returnsSecretStrobjects for API-key fields rather than their underlying string values. Equality still works (SecretStr.__eq__comparesget_secret_value()), so this is correct for common configurations. However, if any LLM field holds a mutable or non-deterministically-ordered structure (e.g., a customextra_headersdict that was built in different ways), the comparison could produce a false positive (two functionally identical LLMs treated as different). This is a low-probability edge case, but worth a brief comment so reviewers understand the intended semantics: