LLMling¶
Declarative resources, prompts and tools for LLM applications, defined in YAML.
LLMling turns a YAML file into a runtime that serves content (resources), message templates (prompts) and Python callables (tools) to an LLM consumer. It was built as the backend for mcp-server-llmling and llmling-agent; its ideas live on in agentpool.
Installation¶
Optional extras: llmling[git] (repository resources), llmling[watch_files]
(file watching via watchfiles), llmling[fsspec_extras] (HTTP/GitHub filesystems).
Quickstart¶
Define an environment in config.yml:
resources:
greeting:
type: text
content: "Hello from LLMling!"
notes:
type: path
path: "./notes.md"
description: "Project notes"
tools:
word_count:
import_path: "my_tools.word_count" # any importable callable
description: "Count words in a text"
prompts:
summarize:
type: text
description: "Summarize a text"
messages:
- role: system
content: "You are a concise assistant."
- role: user
content: "Summarize this:\n{text}"
arguments:
- name: text
description: "Text to summarize"
required: true
With my_tools.py on the import path:
Use it from Python:
import asyncio
from llmling import RuntimeConfig
async def main() -> None:
async with RuntimeConfig.open("config.yml") as runtime:
print(runtime.list_resource_names()) # ['greeting', 'notes']
resource = await runtime.load_resource("greeting")
print(resource.content) # Hello from LLMling!
count = await runtime.execute_tool("word_count", text=resource.content)
print(count) # 3
messages = await runtime.render_prompt("summarize", {"text": resource.content})
for message in messages:
print(message.role, message.get_text_content())
asyncio.run(main())
Or from the command line:
llmling config init my_config.yml # create a starter config
llmling config add myconfig my_config.yml # store it under a name
llmling config set myconfig # make it the active config
llmling resource list -c config.yml
llmling resource load greeting -c config.yml
llmling tool call word_count text="a b c" -c config.yml
llmling prompt show summarize -c config.yml
Features¶
- Resources:
path(files, directories, globs, any fsspec/UPath URL, optional file watching),text,cli(command output),source(Python module source),callable(return value of a Python function) andrepository(files from a git repo). Resources can be grouped (resource_groups) and run through processors. - Prompts: static message templates (
type: text), function-based prompts (type: function, arguments derived from the signature and docstring) and file-based prompts (type: file), with argument validation and completions. - Tools: any importable callable becomes a tool with an OpenAI-compatible schema.
Toolsets add collections of tools from OpenAPI specs (
type: openapi), entry points (type: entry_points) or customToolSetclasses (type: custom). - Processors: function-based and Jinja2 processors to transform resource content.
- Runtime registration: register resources, tools and prompts at runtime via
RuntimeConfig(register_tool,register_static_prompt, ...). - Dependencies:
global_settings.requirementsand PEP 723scriptsdeclare packages needed by tools and prompts. - Typed: pydantic models throughout; a JSON schema for the config format lives in
schema/config-schema.json.
More resource and toolset examples¶
global_settings:
requirements: ["myapp"] # installed on demand if missing
resources:
python_files:
type: path
path: "./src/**/*.py"
watch:
enabled: true
patterns: ["*.py", "!**/__pycache__/**"]
git_changes:
type: cli
command: "git diff HEAD~1"
shell: true
timeout: 5.0
utils_module:
type: source
import_path: myapp.utils
recursive: true
system_info:
type: callable
import_path: platform.uname
resource_groups:
code_review: [python_files, git_changes]
toolsets:
petstore:
type: openapi
spec: "https://petstore3.swagger.io/api/v3/openapi.json"
my_plugins:
type: entry_points
module: myapp
Further reading¶
The docs/ folder contains longer guides on the YAML configuration, resources, prompts, tools and the CLI. The API reference is on the documentation site.