LLMStrategy capabilities (serializable + registerable) + pydantic-ai v2#784
Draft
jduerholt wants to merge 1 commit into
Draft
LLMStrategy capabilities (serializable + registerable) + pydantic-ai v2#784jduerholt wants to merge 1 commit into
jduerholt wants to merge 1 commit into
Conversation
…to pydantic-ai v2
Introduces a capability system for the LLM recommender, mirroring the existing
LLM-provider triplet (data model + tagged union + mapper + register). Capabilities
are typed, serializable config; the mapper rebuilds the live pydantic-ai capability
(including its tool functions) at runtime.
- Data model: LLMCapability base + ExperimentAccessCapability, AnyLLMCapability
union, register_llm_capability(); LLMStrategy gains a capabilities field
(default-on ExperimentAccessCapability via default_factory).
- Functional: bofire/llm/capabilities_mapper.py (CAPABILITY_MAP/register/map) and
experiment_tools.py (FunctionToolset: recent/top/near/summary/pending). Strategy
deps refactored from _LLMDeps to LLMContext (domain + experiments + pending
candidates). The output_validator feasibility gate is unchanged.
- Experiment presentation is now tool-only: removed n_recent_experiments /
n_top_experiments and the prompt-dump path; the model inspects experiments on
demand via tool calls, with counts surfaced in the capability instructions.
- pydantic-ai v2 migration: output_retries -> retries={"output": N},
OpenAIModel -> OpenAIChatModel, pin pydantic-ai>=2,<3.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings the LLM recommender to the next level: a serializable + registerable capability system for
LLMStrategy, plus migration to pydantic-ai v2. Capabilities are typed, serializable config; a mapper reconstructs the live pydantic-ai capability (including its tool functions) at runtime — mirroring the existing LLM-provider triplet (data model + tagged union + mapper +register).As the first capability, experiment presentation moves from a prompt-dump (with
n_recent/n_topknobs) to a tool-onlyExperimentAccessCapabilitythe model queries on demand.What's included
Capability triplet (mirrors
AnyLLMProvider+LLM_MAP+register_llm_provider)bofire/data_models/llm/capability.py—LLMCapabilitybase +ExperimentAccessCapabilityAnyLLMCapabilityunion +register_llm_capability();LLMStrategy.capabilitiesfield (default-on viadefault_factory, replace-semantics documented)bofire/llm/capabilities_mapper.py—CAPABILITY_MAP+register/mapbofire/llm/experiment_tools.py—FunctionToolsetofinspect_recent/inspect_top/inspect_near/summary_stats/list_pending_candidates; per-query logic in unit-testable pure functionsTool-only experiment access
n_recent_experiments/n_top_experimentsand the prompt-dump path_LLMDeps→LLMContext(domain + experiments + pending candidates)output_validatorfeasibility gate is unchanged — capabilities enrich, never bypassdomain.validate_candidatespydantic-ai v2 migration
output_retries→retries={"output": N},OpenAIModel→OpenAIChatModel, pinpydantic-ai>=2,<3Design notes
MCPCapability, RAG, BO-as-a-tool, sandboxed code analysis) drop into the same slot without redesign.Verification
1418 passed, 5 skippedacrosstests/bofire/data_models,test_llm,bofire/llm,test_register(incl. exact serialization round-trip for the default capability)ruff checkclean, formatted;ty check bofireexits 0 (new modules produce zero diagnostics)Follow-ups (out of scope)
asyncio.run()in_askthrows inside a running event loop (Jupyter); matters more once a deep/agentic harness lands.🤖 Generated with Claude Code