Skip to main content
Glama

Deadwax

CI

一个基于个人收听历史的智能体音乐图书管理员。它回答关于你听过什么的自然语言问题,并根据硬约束构建播放列表——带有确定性验证器、修复循环,以及报告通过率而非通过/失败的评估套件。

作为展示生产级 LLM 工程实践的作品集项目而构建:工具使用、检索、追踪、评估和 MCP。

有趣的部分

大多数 LLM 演示在运行两次之前都有效。Deadwax 是围绕第二次运行时发生的情况构建的。

系统沿一条线划分:模型从不计算。 它解释语言、选择工具并撰写文本。每个算术运算、阈值检查和约束裁决都发生在不知道 LLM 存在的纯 Python 中。当播放列表违反约束时,验证器不会返回 False——它返回违规代码、违规曲目 ID 和具体补救措施,这是自动化修复循环能够工作的唯一原因。

可行性在生成之前检查。如果无法满足需求,系统会明确说明。它从不填充、替换或静默降级——status="infeasible" 是一个正确的结果,并有自己的评估用例。

Related MCP server: YouTube Music MCP Server

架构规则

不是风格偏好。违反其中任何一条都会破坏项目的目标。

  1. 模型从不计算。

  2. 工具描述是行为控制——它们是提示词,不是文档。更改工具描述是行为变更,在合并前需要重新评估。

  3. 违规是机器可操作的:一个代码、违规 ID、一个补救措施。绝不只是单纯的布尔值,绝不只是文字。

  4. 可行性在生成之前检查。

  5. 失败是有效的结果。

  6. 硬约束被测量和执行。软约束被推断和评分,并带有 provenance 字段,任何关于它们的消息都必须披露该字段。

  7. 没有追踪就没有模型调用。

决策及其权衡记录在 docs/adr 中。

技术栈

一切都在免费层上运行。这是一个硬约束,不是偏好。

层

选择

语言

Python 3.13

工具链

uv 用于依赖和 Python 本身,ruff 用于 lint 和格式化,pytest

智能体

LangChain,在第 3 阶段引入,不早于此

模型

Google Gemini Flash,带 OpenRouter 回退

存储

通过 sqlite3 标准库模块使用 SQLite

检索

构建时嵌入,纯 Python 中的余弦相似度——无向量数据库

追踪

Langfuse

互操作

Model Context Protocol 服务器

前端

Cloudflare Pages 上的 Astro——唯一的 JavaScript 组件

第 0 到第 2 阶段仅使用标准库——没有框架、没有 SDK、没有依赖。在引入任何抽象之前,原始 HTTP 调用是手工编写的,因此当框架歪曲其行为时,差异是可见的。

构建进度

十二个阶段,四个阶段组。每个阶段一个分支和一个 squash 合并的 PR,因此历史记录读起来就像构建实际发生的过程。

阶段组

阶段

状态

A · 基础

0 · 一次原始调用

🔨 进行中

A · 基础

1 · 固定数据

⬜

A · 基础

2 · 确定性核心

⬜

B · 智能体

3 · 第一个工具循环

⬜

B · 智能体

4 · 测量波动

⬜

B · 智能体

5 · 评估框架

⬜ v0.5

C · 打磨

6 · 修复循环

⬜

C · 打磨

7 · 对抗性用例

⬜

C · 打磨

8 · 追踪

⬜

C · 打磨

9 · 检索

⬜ v0.9

D · 发布

10 · 真实数据

⬜

D · 发布

11 · MCP 服务器

⬜

D · 发布

12 · 网站和文章

⬜ v1.0

运行

你需要 uv。它安装并管理 Python 本身,因此它是唯一的先决条件。

winget install --id=astral-sh.uv -e

然后,从仓库根目录:

uv sync

这会创建一个虚拟环境,从 .python-version 安装固定的 Python 版本,并安装项目。

从 Google AI Studio 添加免费的 Gemini API 密钥:

copy .env.example .env

将密钥粘贴到 GEMINI_API_KEY= 后面。然后查看你的密钥可以访问哪些模型,因为免费层的目录会随时更改,恕不另行通知:

uv run scripts/raw_call.py --list

将其中一个 ID 作为 GEMINI_MODEL 放入 .env,然后发起调用:

uv run scripts/raw_call.py

它在提取答案之前打印完整的请求和完整的响应。这就是脚本的意义所在——在框架隐藏它们之前,这些结构值得了解。

你账户的实际速率限制显示在 aistudio.google.com/rate-limit;Google 不再在 API 文档中发布按模型划分的免费层表格。

评估

评估套件在第 5 阶段落地。用例是手工编写的,从不生成——如果同一个工具既编写代码又编写评分,那么分数毫无意义。分数以多次运行的通过率报告,因为在非确定性系统上的一次通过只是一个轶事。

任何更改提示词、工具描述或模型的提交,其消息中都会包含评估前后的分数。

许可证

MIT。参见 LICENSE。

由 David Koen 构建。

Available Tools

4 tools
check_feasibilityA
Read-only

Check whether a playlist brief is possible at all, before choosing any tracks.

Call this first, before query_library, whenever the user asks for a playlist with constraints. If feasible is false the brief cannot be satisfied by this library: tell the user which constraint fails and stop. Do not build a playlist anyway, do not relax the constraint yourself, and do not try alternative track combinations.

max_achievable_display is the longest playlist the library can produce under these constraints. When explaining a refusal, describe what the user asked for in their own words and quote max_achievable_display for what is possible. Never show the user a millisecond figure and never convert one yourself.

A brief with no constraints at all cannot be checked. If the user has not said how long the playlist should be or what should be in it, ask them before calling this.

NameRequiredDescriptionDefault
released_afterNo
released_beforeNo
required_genresNo
max_track_duration_msNo
max_tracks_per_artistNo
min_total_duration_msNo

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare a safe read-only, closed-world operation, and the description goes well beyond them: it discloses the 'feasible' boolean and 'max_achievable_display' return semantics, plus a refusal protocol and a presentation rule (never surface or convert millisecond figures). That is real behavioral context an agent could not infer from readOnlyHint alone.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core purpose and the sequencing rule, and most sentences add distinct policy. The refusal paragraph slightly over-enumerates ('do not build a playlist anyway, do not relax the constraint yourself, and do not try alternative track combinations'), which are three phrasings of one instruction.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a six-parameter, no-output-schema tool the usage and refusal policy are complete, but the description omits any explanation of the parameter formats an agent must supply, which is the main remaining risk. It explains two return fields but not the full result shape.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description carries the full burden for six parameters, yet it never explains any of them. It is ambiguous whether released_after/released_before are years or epoch timestamps, and units for max_track_duration_ms and min_total_duration_ms are only obliquely implied by the millisecond warning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('check whether a playlist brief is possible') and positions it temporally ahead of track selection, which distinguishes it from query_library and validate_playlist. An agent knows immediately that this is a pre-flight gate, not a builder or validator.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit when-to-call ('first, before query_library, whenever the user asks for a playlist with constraints'), explicit when-not ('a brief with no constraints at all cannot be checked — ask them before calling'), and explicit failure behavior ('tell the user which constraint fails and stop', 'do not relax the constraint yourself'). Alternatives and exclusions are both covered.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

enrich_artistA
Read-only

Look up background on one artist in the user's library, from published sources.

Call this for any question about an artist's history, members, origins, influences or career. Pass the artist's name and the user's question. It returns the passages from MusicBrainz and Wikipedia that best match the question.

Answer only from these passages. If they do not contain the answer, tell the user your sources do not cover it, even if you believe you know. Never fill the gap from your own knowledge.

Cite every passage you use by its id in square brackets, such as [can-03], straight after the claim it supports. Never cite an id this tool did not return.

This tool knows nothing about the user's tracks. Use query_library for those.

NameRequiredDescriptionDefault
artistYes
questionYes

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the readOnly/openWorld annotations by disclosing the data sources (MusicBrainz, Wikipedia), the grounding contract (answer only from returned passages, refuse otherwise), and the citation protocol required in the reply. These are response-shaping rules the annotations cannot convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose, then usage, then output contract, then sibling routing. Every sentence adds an actionable rule; nothing is redundant with the schema or annotations.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, and the description supplies the return shape ('passages ... that best match the question') along with the id format used in citations. An agent has everything needed to call it and to post-process the result correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate, and it does: 'artist' is clarified as the name and 'question' as the user's question, which implies phrasing the question in natural language rather than keywords. It stops short of format examples or naming conventions for the artist string.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('look up background on one artist ... from published sources') and names the sources. The final sentence explicitly separates it from query_library, so an agent can route without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit trigger ('any question about an artist's history, members, origins, influences or career') and an explicit exclusion plus alternative ('This tool knows nothing about the user's tracks. Use query_library for those.'). Both when and when-not are covered.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

query_libraryA
Read-only

Search the user's music library and return matching tracks with their totals.

Call this before stating any fact about the library. Never estimate a count, a duration or a track name from your own knowledge, and never add numbers up yourself: use total_matching and total_duration_ms from the result, which are computed exactly. The tracks list is truncated to limit entries, so it may be shorter than total_matching.

To find a longest, shortest, highest or lowest track, pass order_by as one of longest, shortest, highest_energy, lowest_energy and read the first entry. Never rank, compare or pick a maximum out of the list yourself; the ordering is computed here.

Quote duration_display for a track and total_duration_display for a set of them. Never convert milliseconds to minutes yourself.

Energy is an estimate, not a measurement. Every track carries energy_provenance saying where its value came from, and any answer that mentions energy must say it is an estimate.

If a genre search finds nothing, known_genres lists the genre tags the library actually uses. If the user's word is another name for one of them, as rap is for hip hop, search again with that tag and say which tag you searched. Never substitute a genre that is merely related.

NameRequiredDescriptionDefault
genreNo
limitNo
artistNo
playedNo
order_byNo
released_afterNo
max_duration_msNo
min_duration_msNo
released_beforeNo

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already establish read-only and non-destructive behavior, but the description adds substantial behavioral context beyond that: the tracks list is truncated to limit, totals are computed exactly, ordering is computed server-side, energy is an estimate with provenance, and genre fallback is available. These details materially change how an agent should interpret and present results.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core action and key rules, and most sentences carry actionable guidance. It is somewhat long and repeats the same anti-estimation theme across multiple sentences, which costs some conciseness, but the structure remains purposeful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema, so the description appropriately explains key return fields such as total_matching, total_duration_ms, tracks, duration_display, and energy_provenance. However, for a 9-parameter tool with 0% schema description coverage, it leaves important input filters undocumented, so the overall context is only partially complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% and there are 9 parameters, so the description must carry the burden of explaining them. It adds meaning for order_by values, genre fallback behavior, and limit truncation, but it does not explain artist, played, released_after, released_before, min_duration_ms, or max_duration_ms, leaving more than half of the parameters undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: search the user's music library and return matching tracks with totals. It is immediately distinguishable from the sibling tools validate_playlist, enrich_artist, and check_feasibility, which serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives explicit usage rules: call before stating any fact about the library, never estimate counts or durations, use total_matching and total_duration_ms, and pass order_by for longest/shortest/highest/lowest queries. It also explains the genre fallback path and when to search again with known_genres. The guidance is unusually complete for an agent.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

validate_playlistA
Read-only

Check a proposed playlist against hard constraints and report every violation.

Call this before presenting any playlist to the user. Do not judge for yourself whether a playlist meets its constraints. Each violation names the offending track ids and an adjust_by amount in the constraint's own unit: negative means remove that much, positive means add that much. Act on adjust_by rather than guessing how much to change.

When describing the playlist, quote track_count and total_duration_display from this result verbatim. Never sum durations yourself and never convert milliseconds to minutes yourself.

A duration violation also carries adjust_by_display, the same amount written in minutes and seconds. Show the user that, never the millisecond figure.

Pass the same release-year bounds you gave check_feasibility, so a track outside the window is caught here too.

If the user asks for an energy level or a mood, pass target_energy between 0 and 1. It is scored, never enforced: soft_scores reports how close the playlist came, and because energy is estimated rather than measured, any answer that mentions it must say so.

NameRequiredDescriptionDefault
track_idsYes
target_energyNo
released_afterNo
released_beforeNo
required_genresNo
max_total_duration_msNo
max_track_duration_msNo
max_tracks_per_artistNo
min_total_duration_msNo

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already establish that this is a safe read (readOnlyHint=true, destructiveHint=false), and the description adds substantive behavior the annotations cannot convey: violation records carry track ids and a signed adjust_by in the constraint's unit, duration violations also carry adjust_by_display, and target_energy is scored rather than enforced. It also warns that energy is estimated and must be disclosed, which is a real behavioral constraint on downstream answers.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The most important directive (what the tool does, and call it before presenting) is front-loaded, and every subsequent paragraph carries a distinct instruction: adjust_by semantics, verbatim quoting rules, cross-tool bound reuse, and energy caveat. It is on the long side for a nine-parameter tool, but no sentence is redundant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description has to sketch the return shape and it does: violations, adjust_by, adjust_by_display, soft_scores, track_count, total_duration_display. The remaining gap is the unmentioned constraint parameters, which an agent must guess from their names alone.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description carries the full burden. It explains target_energy well (0-1 range, scored not enforced, soft_scores output) and gives intent for released_after/released_before by tying them to check_feasibility, but required_genres, max_total_duration_ms versus min_total_duration_ms, max_track_duration_ms, and max_tracks_per_artist are never mentioned — half the parameters remain opaque.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource (check a proposed playlist against hard constraints) plus the scope of the output (report every violation). It implicitly separates itself from check_feasibility by instructing the caller to reuse the release-year bounds given to that sibling, so an agent can tell the two apart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit temporal gating ('Call this before presenting any playlist', 'Do not judge for yourself'), an explicit cross-tool dependency ('Pass the same release-year bounds you gave check_feasibility'), and an explicit conditional trigger ('If the user asks for an energy level or a mood, pass target_energy'). Nothing is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedcheck_feasibility
    • First observedenrich_artist
    • First observedquery_library
    • First observedvalidate_playlist

TDQS

A4.5/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct role: check_feasibility checks a brief before track selection, query_library searches local tracks, validate_playlist checks a proposed playlist, and enrich_artist retrieves external artist background. The descriptions explicitly distinguish the two check-style tools by workflow phase and data source.

Naming Consistency5/5

All four names follow a consistent snake_case verb_noun pattern: validate_playlist, enrich_artist, check_feasibility, query_library. The verbs are distinct and predictable for their actions.

Tool Count5/5

Four tools is well-scoped for a focused playlist-assistant server, with each tool covering a separate workflow stage. There is no redundant or filler tool.

Completeness4/5

The set covers feasibility checking, library search, playlist validation, and artist enrichment, which supports the core playlist-building workflow. Minor gaps remain around explicitly creating, saving, or exporting a playlist, but agents can work around this by presenting validated playlists.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers