feat: add tools with instructions and examples to completion and agent configs#106
feat: add tools with instructions and examples to completion and agent configs#106
Conversation
Co-Authored-By: Paul Loeb <ploeb@launchdarkly.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
make sure to add test coverage and verify the tests pass |
Co-Authored-By: Paul Loeb <ploeb@launchdarkly.com>
|
Note: This PR needs the |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| ) | ||
| for tool in variation['tools'] | ||
| if isinstance(tool, dict) and 'key' in tool | ||
| ] or None |
There was a problem hiding this comment.
Duplicated tool-parsing logic across two methods
Low Severity
The tool-parsing block in _completion_config and __evaluate_agent is completely identical — same list comprehension, same AITool construction, same filter, same or None coercion. This duplication means any future bug fix or field addition needs to be applied in both places, risking divergence. Extracting to a shared helper (similar to how __evaluate is shared) would eliminate this risk.
Additional Locations (1)
There was a problem hiding this comment.
Valid observation. The duplication is intentional to keep the shared __evaluate method unchanged and limit blast radius. Extracting to a helper is a reasonable follow-up refactor but deferring for now to keep this PR focused on the feature addition.
Co-Authored-By: Paul Loeb <ploeb@launchdarkly.com>


Requirements
Related issues
Part of a coordinated multi-repo change to add
instructionsandexamplesfields to AI Tools. Companion PRs:Describe the solution you've provided
Adds a new
AITooldataclass and wires tools through both completion and agent configurations so the SDK can surface tool metadata (including the newinstructionsandexamplesfields) returned by the LaunchDarkly API.Changes:
models.py: New frozenAITooldataclass withkey,version,instructions,examples, andcustom_parametersfields. Addedtools: Optional[List[AITool]]toAIAgentConfig,AIAgentConfigDefault,AICompletionConfig, andAICompletionConfigDefault, with serialization support in allto_dict()methods.client.py: Both_completion_configand__evaluate_agentnow parsetoolsfrom the variation dictionary, constructingAIToolinstances. Falls back todefault.toolswhen the variation has no tools.__init__.py: ExportsAITool.tests/test_tools.py: 14 new tests covering tool parsing, serialization, default fallback, and edge cases for both completion and agent configs.Updates since last revision
toolsfield toAICompletionConfigandAICompletionConfigDefault(previously only on agent configs)_completion_configinclient.pynow parses tools from variation data, mirroring the agent patterntest_tools.py) — all 91 tests pass (14 new tool tests + 77 existing)_completion_config(lines ~59-72) and__evaluate_agent(lines ~733-745) is identical. Consider extracting to a shared helper if this is a concern.[...] or None): if all tools fail the filter, the result isNonerather than[]. Verify this is the desired behavior.tool.get('version', 0)): tools missing aversionkey silently default to 0. Confirm this is acceptable vs raising or skipping.tools if tools is not None else (default.tools if default.tools else None)is equivalent totools if tools is not None else default.toolssincedefault.toolsalready defaults toNone.Describe alternatives you've considered
__evaluatelevel (alongside messages, model, etc.) instead of in both_completion_configand__evaluate_agent. Chose per-method parsing to keep the shared__evaluatemethod unchanged and limit blast radius.Additional context
Note
Medium Risk
Moderate risk because it changes the shape and parsing/serialization of returned config objects (
completion_config/agent_config), which could affect downstream consumers and default/fallback behavior (notably distinguishing missingtoolsfrom an explicit empty list).Overview
Adds a new frozen
AIToolmodel (includinginstructions,examples, andcustomParameters) and wirestoolsthrough both completion and agent config types (AICompletionConfig*,AIAgentConfig*) withto_dict()support.Updates
LDAIClientto parse atoolsarray from flag variation payloads in_completion_configand__evaluate_agent, falling back todefault.toolsonly when the server does not sendtools(while preserving an explicit empty list), and exportsAIToolfromldai.__init__.Adds
tests/test_tools.pyto cover tool parsing, serialization, default fallback, and empty/missing tool edge cases for both completion and agent configs.Written by Cursor Bugbot for commit 0996e4e. This will update automatically on new commits. Configure here.