Skip to content

Commit

Permalink
feat: more sophisticated capability setup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Dec 10, 2024
1 parent 664cae5 commit df03856
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
52 changes: 41 additions & 11 deletions schema/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
26 changes: 21 additions & 5 deletions src/llmling/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 13 additions & 7 deletions src/llmling/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit df03856

Please sign in to comment.