This commit is contained in:
Brent Larsen
2026-10-07 09:27:20 -05:00
parent cf1ab0a7af
commit bf02eff6ea
12 changed files with 808 additions and 91 deletions
+55
View File
@@ -0,0 +1,55 @@
# Perry history
This file records why Perry changed, not every mechanical code edit.
## Conversation history became the session
The original problem was practical: build a chat client around Ollama whose sessions could be persisted, branched, and have information injected into them.
No extra session architecture was necessary. The provider already accepted conversation history in a JSON-friendly shape. Persisting that history persisted the session. Copying the history created a branch. Inserting or composing portions of history altered what the model knew.
Reusable conversation subsets became "Legos." Ordered collections of them became "Lego Towers." The useful technique emerged from ordinary chat history rather than from a new agent/session framework.
That remains a foundational Perry decision.
## Chat2 became reusable infrastructure
Several application pipelines independently needed the same mechanics around local LLM calls: prepared conversational agents, streaming reasoning and content, transport retries, incomplete-response continuation, and persistent conversation history.
The repeated implementation became Chat2 and was later extracted as Perry so applications could own domain behavior while sharing the mechanics of operating an LLM-backed conversational agent.
## LM Studio became the surviving provider
The older lineage supported Ollama, but the code available when Perry was extracted contained only the active LM Studio Responses API implementation. Perry documented that fact instead of reconstructing an Ollama provider from memory.
This is intentional simplicity: provider-neutral scope does not require speculative provider implementations.
## Repetition self-destruct
Real LM Studio/model runs demonstrated a catastrophic failure mode where a generation could fall into an exact repeating token orbit indefinitely. A deliberately conservative detector was added to the LM Studio streaming implementation.
It checks the reasoning and final-content channels independently and aborts only after an exact token sequence has repeated seven complete times. The normal retry layer can then restart the response without adding the pathological partial response to conversation history.
The behavior is intentionally provider-specific until multiple provider implementations demonstrate that a shared abstraction is useful.
## Perry 0.2: consolidate lessons from the family
The application family continued evolving after Perry was extracted. A Coptic guide pipeline learned that LM Studio model warmup failures must be fatal: continuing after a requested model cannot load allows expensive downstream work to run under false assumptions.
At the same time, Perry itself had acquired repetition protection that the copied Chat2 implementations did not contain. The divergence demonstrated why LLM transaction mechanics should have one home.
Perry 0.2 consolidates those lessons and clarifies the boundary:
- Perry is provider-neutral, not "local-model" infrastructure.
- Perry is constructed directly from explicit `provider` and `model` settings and has no dependency on Optimus.
- Instances are lightweight and may be created freely.
- `client` was deliberately replaced by `provider`; no compatibility alias was retained while the family is being revisited together.
- LM Studio warmup now fails fast when the requested model cannot be made available.
- Availability is checked before each request attempt rather than cached for the life of a Perry instance.
- The exact model requested by the consumer is the model Perry requests. Application aliases belong upstream.
- If LM Studio explicitly identifies a different response model, the response is rejected rather than treated as equivalent.
- The unused reasoning-effort configuration lever was removed. Reasoning streaming remains supported.
- Perry no longer writes reasoning, content, retries, continuations, or other user-facing messages to the console. Consumers own their UI and logging.
- Existing continuation, retry, provider diagnostics, Lego formation, and LM Studio repetition behavior were retained.
The goal was consolidation, not redesign. Downstream applications can keep their current orchestration shape and wrap Perry locally if that minimizes change.
+31
View File
@@ -0,0 +1,31 @@
# Ideas and deferred work
These are observations worth retaining, not promises or roadmap commitments. Do not implement them merely because they are written here. Revisit them when real work makes them relevant.
## Retry and model recovery
Current Perry transport behavior allows up to ten retries before giving up.
A real failure pattern suggests a potentially better strategy: after roughly four consecutive failures, explicitly recover or reload the requested model, then allow another small group of attempts rather than blindly repeating the same failing request ten times.
This has not been implemented in Perry 0.2. The existing retry behavior is transparent to consumers and remains serviceable. Before changing it, inspect current failures and discuss what "recover/reload" means for the active provider rather than designing a provider-wide recovery framework in advance.
## Additional providers
Ollama existed in Perry's Chat2 ancestry and was useful when it was being used. No active implementation exists in the current repository, so it was not recreated.
If Ollama or another provider becomes useful again, implement the concrete provider required by that work. Do not pre-build generalized provider infrastructure first.
Likewise, a future Perry provider might not be a network client at all. A local Python-backed model runtime could still be a Perry provider if it satisfies the actual need. That possibility does not justify architecture today.
## Additional settings
Possible LLM controls include context size, output token limits, temperature, reasoning effort, provider endpoints, and many others.
None should be added to Perry merely because they exist. Add a setting when a real consumer needs to control it and the responsibility clearly belongs at the Perry boundary.
## Shared provider behavior
Some behavior currently lives inside the LM Studio provider, including exact repetition-loop detection and stream abortion.
Do not extract a generic interface after a second vaguely similar implementation. A useful working heuristic is to wait until about three real implementations reveal substantially the same shape, then decide whether there is actually a common concept worth naming.
+84
View File
@@ -0,0 +1,84 @@
# Intentional behavior
These are deliberate Perry behaviors and boundaries, not incidental implementation details. Do not remove, generalize, or substantially alter them during cleanup or refactoring without discussion.
## Perry is the LLM boundary, not the application
Perry handles LLM transaction mechanics. Consumers decide who agents are, which Legos form them, why a request exists, what an answer means, and what happens next.
Do not move pipeline stages, translation semantics, artifact logic, domain validation, or agent personas into Perry merely because they are adjacent to an LLM call.
## Perry is independent of Optimus
Perry must not import Optimus, read Optimus settings, or provide an Optimus-specific adapter. Optimus must not be required by Perry.
An Optimus application may create its own local module that reads application settings, constructs Perry, and exposes whatever interface is convenient to that application.
## Perry instances are cheap
Construction does not open an expensive persistent connection, load a model, register global state, or create a resource that needs special disposal.
Consumers may use one Perry instance or many. Do not introduce singleton assumptions or application-global model state.
## Settings are small and explicit
Current settings are exactly the concepts Perry has evidence to own:
- `provider`
- `model`
Both are required. `provider` replaced the older `client` name deliberately.
Do not add settings merely because an underlying provider exposes options. Provider capabilities do not automatically become Perry configuration.
## Exact model means exact model
Perry does not know model aliases or equivalence classes.
Before a request, an implemented provider should use any certainty it actually possesses to establish that the exact configured model can handle the work. If it can prove that model is unavailable or another model would be used, fail before inference. If the provider cannot know, ambiguity is allowed.
After a response, reject a model mismatch only when the provider explicitly supplies enough evidence to know the response came from a different model. Absence of model metadata is not itself failure.
Application-level aliases and model-selection policy belong before Perry construction.
## Lego shape is Perry-owned and provider-neutral
Conversation messages use Perry's known shape. Providers translate that shape into provider-native requests.
Do not pass arbitrary provider-specific message fields through Perry. A provider currently accepting Perry's shape directly does not make that provider's format Perry's public contract.
Conversation subsets are ordinary data. Lego Towers do not require registries, inheritance, graph objects, session managers, or special persistence machinery.
## Reasoning is observable, not conversational authority
When a provider exposes reasoning, Perry may stream it through `onReasoning` and retain it on returned replies for diagnostics.
Reasoning is not normally included when a prior Lego/conversation subset is added to a new active conversation. The model's ordinary conversation context remains role/content history.
## Perry does not speak
Perry does not own console or UI output.
No automatic response printing, reasoning headings, retry messages, continuation messages, warnings, or progress output should be added to Perry. Consumers can use callbacks, return values, errors, and provider diagnostics to decide what to display or log.
## Automatic continuation is intentional
Provider-native incomplete responses are continued automatically when it can be done safely. If provider-native continuation is unavailable and the model produced reasoning without final content, Perry may continue through explicit conversation history.
Partial failed responses are not silently appended as successful conversation turns.
## Retry behavior is intentionally conservative and currently imperfect
Transient transport failures currently retry up to ten times with the existing backoff. Non-retryable failures, including known model availability/identity failures, stop immediately.
The ten-attempt strategy is not considered perfected or permanent. It remains because changing it is a separate behavioral decision; see `ideas.md`.
## LM Studio repetition protection is intentionally local
Exact repetition-loop detection lives in the LM Studio implementation because LM Studio is the concrete provider where the failure has been observed and implemented.
Do not manufacture a provider-wide repetition/cancellation interface from this single example. Generalize only after repeated real implementations expose the same natural boundary.
## Blocking boundary is the intended direction
Applications in this project family are synchronous blocking batch tools. Perry may need to deal with provider-level asynchronous transport internally, but that should eventually be hidden behind a blocking application-facing boundary with bounded timeout behavior. Existing Promise/callback APIs are legacy plumbing, not a desired architecture to extend.