refactor(#2804): model-layer cleanup — RESERVED_MEMORY_TOOL_NAMES reu…#75
Merged
Conversation
…se, named constants, reserveName guard, severity log, AgentEvent dedupe
Five small fixes in the model layer:
Reuse RESERVED_MEMORY_TOOL_NAMES (AgenticLoop.kt)
- The inline `setOf("memory_read","memory_write","memory_search")` was
drifting against the canonical constant in `ToolDef.kt`. AgenticLoop
now imports and uses RESERVED_MEMORY_TOOL_NAMES — adding a 4th memory
tool now updates one set, not two.
Named hash-prefix constants (AgenticLoop.kt)
- `MANIFEST_HASH_PREFIX_LEN = 12` for the OpenAI `prompt_cache_key`
routing hint suffix.
- `BLOB_HASH_PREFIX_LEN = 12` for the content-addressed blob placeholder
rendered into tool-result LLM messages.
Named Anthropic constants (ClaudeClient.kt)
- `ANTHROPIC_MAX_CACHE_BREAKPOINTS = 4` documents the per-request cap
on `cache_control` markers (Anthropic Messages API limit).
- `EPHEMERAL_TTL_BOUNDARY_MINUTES = 5L` documents the boundary between
the default ephemeral cache and the `"ttl":"1h"` long-cache tier.
reserveName guard (ToolDef.kt)
- The "Tool already defined in this tools block" `require(...)` was
duplicated 5× across all `tool(...)` overloads and the `unaryPlus`
operator. Extracted to `MutableList<ToolDef>.reserveName(name)` —
one definition, one place to change if uniqueness semantics evolve.
Severity parse log (ToolDef.kt)
- `Severity.valueOf(severityStr)` previously fell through to HIGH on
any exception (including IllegalArgumentException from an unknown
enum value) without telemetry. Now logs at WARNING when the LLM
supplies an unknown severity, preserving the safe HIGH default
while making the misuse visible.
AgentEvent.ToolCallFinished emit dedupe (AgenticLoop.kt)
- Four near-identical emit blocks (unknown-tool, denied, success,
executor exception) replaced with calls to a private
`emitToolFinished(emitter, agent, call, result, isError)` helper.
- Removed all five `agents_engine.runtime.events.AgentEvent.…` FQN
references; the import has been at the top of the file all along.
Full ./gradlew test green; 254+ TEST-*.xml files, zero failures/errors.
Co-Authored-By: Claude Opus 4.7 (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.
…se, named constants, reserveName guard, severity log, AgentEvent dedupe
Five small fixes in the model layer:
Reuse RESERVED_MEMORY_TOOL_NAMES (AgenticLoop.kt)
setOf("memory_read","memory_write","memory_search")was drifting against the canonical constant inToolDef.kt. AgenticLoop now imports and uses RESERVED_MEMORY_TOOL_NAMES — adding a 4th memory tool now updates one set, not two.Named hash-prefix constants (AgenticLoop.kt)
MANIFEST_HASH_PREFIX_LEN = 12for the OpenAIprompt_cache_keyrouting hint suffix.BLOB_HASH_PREFIX_LEN = 12for the content-addressed blob placeholder rendered into tool-result LLM messages.Named Anthropic constants (ClaudeClient.kt)
ANTHROPIC_MAX_CACHE_BREAKPOINTS = 4documents the per-request cap oncache_controlmarkers (Anthropic Messages API limit).EPHEMERAL_TTL_BOUNDARY_MINUTES = 5Ldocuments the boundary between the default ephemeral cache and the"ttl":"1h"long-cache tier.reserveName guard (ToolDef.kt)
require(...)was duplicated 5× across alltool(...)overloads and theunaryPlusoperator. Extracted toMutableList<ToolDef>.reserveName(name)— one definition, one place to change if uniqueness semantics evolve.Severity parse log (ToolDef.kt)
Severity.valueOf(severityStr)previously fell through to HIGH on any exception (including IllegalArgumentException from an unknown enum value) without telemetry. Now logs at WARNING when the LLM supplies an unknown severity, preserving the safe HIGH default while making the misuse visible.AgentEvent.ToolCallFinished emit dedupe (AgenticLoop.kt)
emitToolFinished(emitter, agent, call, result, isError)helper.agents_engine.runtime.events.AgentEvent.…FQN references; the import has been at the top of the file all along.Full ./gradlew test green; 254+ TEST-*.xml files, zero failures/errors.