From df038561e7ffa03dadc154eed4a35146814b279e Mon Sep 17 00:00:00 2001 From: Philipp Temminghoff Date: Tue, 10 Dec 2024 15:25:53 +0100 Subject: [PATCH] feat: more sophisticated capability setup --- schema/config-schema.json | 52 +++++++++++++++++++++++++++-------- src/llmling/config/models.py | 26 ++++++++++++++---- src/llmling/config/runtime.py | 20 +++++++++----- 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/schema/config-schema.json b/schema/config-schema.json index 4b66212..abfd9a5 100644 --- a/schema/config-schema.json +++ b/schema/config-schema.json @@ -481,17 +481,9 @@ "$ref": "#/$defs/Jinja2Config", "description": "Jinja2 environment configuration" }, - "enable_resource_tools": { - "default": true, - "description": "Whether to register tools for resource loading/listing", - "title": "Enable Resource Tools", - "type": "boolean" - }, - "enable_tool_management": { - "default": true, - "description": "Whether to register tools for dynamic tool registration and package management", - "title": "Enable Tool Management", - "type": "boolean" + "llm_capabilities": { + "$ref": "#/$defs/LLMCapabilitiesConfig", + "description": "Control which system capabilities are exposed to LLMs." } }, "title": "GlobalSettings", @@ -711,6 +703,44 @@ "title": "Jinja2Config", "type": "object" }, + "LLMCapabilitiesConfig": { + "additionalProperties": false, + "description": "Configuration for LLM system capabilities.", + "properties": { + "load_resource": { + "default": true, + "description": "Whether the LLM can load and access resource content.", + "title": "Load Resource", + "type": "boolean" + }, + "get_resources": { + "default": true, + "description": "Whether the LLM can discover available resources.", + "title": "Get Resources", + "type": "boolean" + }, + "install_package": { + "default": false, + "description": "Whether the LLM can install new Python packages for future tools.", + "title": "Install Package", + "type": "boolean" + }, + "register_tool": { + "default": false, + "description": "Whether the LLM can register importable functions as new tools.", + "title": "Register Tool", + "type": "boolean" + }, + "register_code_tool": { + "default": false, + "description": "Whether the LLM can create new tools from provided Python code.", + "title": "Register Code Tool", + "type": "boolean" + } + }, + "title": "LLMCapabilitiesConfig", + "type": "object" + }, "MessageContent": { "description": "Content item in a message.", "properties": { diff --git a/src/llmling/config/models.py b/src/llmling/config/models.py index c5cce6d..a8d61fa 100644 --- a/src/llmling/config/models.py +++ b/src/llmling/config/models.py @@ -70,6 +70,25 @@ def from_yaml(cls, content: str) -> Self: return cls.model_validate(data) +class LLMCapabilitiesConfig(ConfigModel): + """Configuration for LLM system capabilities.""" + + load_resource: bool = True + """Whether the LLM can load and access resource content.""" + + get_resources: bool = True + """Whether the LLM can discover available resources.""" + + install_package: bool = False + """Whether the LLM can install new Python packages for future tools.""" + + register_tool: bool = False + """Whether the LLM can register importable functions as new tools.""" + + register_code_tool: bool = False + """Whether the LLM can create new tools from provided Python code.""" + + class Jinja2Config(ConfigModel): """Configuration for Jinja2 environment. @@ -200,11 +219,8 @@ class GlobalSettings(ConfigModel): jinja_environment: Jinja2Config = Field(default_factory=Jinja2Config) """Jinja2 environment configuration""" - enable_resource_tools: bool = True - """Whether to register tools for resource loading/listing""" - - enable_tool_management: bool = True - """Whether to register tools for dynamic tool registration and package management""" + llm_capabilities: LLMCapabilitiesConfig = Field(default_factory=LLMCapabilitiesConfig) + """Control which system capabilities are exposed to LLMs.""" class BaseResource(BaseModel): diff --git a/src/llmling/config/runtime.py b/src/llmling/config/runtime.py index d9b0e5c..f96a74a 100644 --- a/src/llmling/config/runtime.py +++ b/src/llmling/config/runtime.py @@ -371,13 +371,19 @@ def from_config(cls, config: Config) -> Self: from llmling.config.llm_tools import LLMTools llm_tools = LLMTools(runtime) - if config.global_settings.enable_resource_tools: - for tool in llm_tools.get_llm_resource_tools(): - tool_registry.register(tool.name, tool) - - if config.global_settings.enable_tool_management: - for tool in llm_tools.get_llm_tool_management_tools(): - tool_registry.register(tool.name, tool) + capabilities = config.global_settings.llm_capabilities + + # Register enabled capabilities + if capabilities.load_resource: + tool_registry["load_resource"] = llm_tools.load_resource + if capabilities.get_resources: + tool_registry["get_resources"] = llm_tools.get_resources + if capabilities.install_package: + tool_registry["install_package"] = llm_tools.install_package + if capabilities.register_tool: + tool_registry["register_tool"] = llm_tools.register_tool + if capabilities.register_code_tool: + tool_registry["register_code_tool"] = llm_tools.register_code_tool return runtime