Commit graph

8 commits

Author SHA1 Message Date
e6830161bc fix(llamacpp,anthropic): SSE headroom, no-choices guard, real context window
- llamacpp: 4MB SSE scanner buffer (the 64KB bufio.Scanner default killed
  streams whose single line exceeded it, e.g. a write tool call carrying a
  whole file) and an empty-choices guard in toResponse instead of a panic;
  request payload now uses bytes.NewReader (drops a full string copy).
- anthropic: Capabilities() reported a 1M-token context window for any
  non-haiku model. Callers use that number to decide when to compact, so
  compaction would have fired far too late and requests overflowed the
  real window. Default is now the standard 200k, configurable via
  Config.ContextWindow for extended-window models/plans.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:14:15 -07:00
838eef642a fix(openai): make streaming actually work; honor configured model
The Stream() path was broken end to end:
- requests always went out with "stream": false, so the SSE parser found
  no data lines and every stream ended empty
- Config.Model was discarded at construction, and the agent loop never
  sets req.Model, so requests carried an empty model (hard API error)
- tool-call deltas were ignored entirely: the agent never executed tools
  over a stream with this provider (which also backs the ollama type)
- usage was neither requested nor parsed, so token tracking stayed at 0

Now mirrors the proven llamacpp client: stream flag + stream_options
.include_usage, per-index tool-call fragment accumulation flushed on
finish_reason, usage passthrough, a 4MB SSE scanner buffer (64KB default
kills the stream on large tool arguments), and an empty-choices guard in
toResponse instead of a panic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:14:01 -07:00
a2de4eb812 feat(llm): add anthropic provider client, expand llama.cpp sampling config
- pkg/llm/providers/anthropic: new client implementation (was previously
  imported by rony-harness but never committed here, so a fresh clone
  wouldn't build)
- pkg/llm/providers/llamacpp: Config/Client gain the full local-model
  sampling surface (max_tokens, context_window, top_k/top_p/min_p,
  presence/repetition penalty, max_thinking_tokens) to match the
  llamacpp-local* entries added to configs/ai_providers.yaml

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 23:33:20 -07:00
3ac9d89b98 Fix tool call tracking and streaming assembly for all providers
- agent/loop.go: Record assistant message with ToolCalls before tool results,
  and set ToolCallID on tool-result messages so follow-up requests have complete
  context (prevents models from losing track of already-attempted tools).

- llm/providers/llamacpp/client.go: Buffer fragmented tool call deltas during
  streaming, assemble them into complete calls when finish_reason arrives.
  Add ToolCalls, ToolCallID, Name fields to request building.

- llm/providers/openai/client.go: Send ToolCalls, ToolCallID, Name when
  building chat requests so messages are wire-format correct.

- llm/types.go: Add ToolCalls field to Message struct for serialization
  back into conversation history.

- agent/integration_test.go: Move integration test skip from TestMain to a
  per-test skipUnlessIntegration() so it doesn't hide other package tests.

- sandbox & tools: Add edge-case tests (relative traversal, array paths,
  non-path strings, zero-value guards, sentinel errors).
2026-07-08 16:11:57 -07:00
0652023037 feat(rag): add SQLite+FTS5 backend, fix content/usage plumbing bugs
Backend.Upsert never received the fragment's Content, so ChromaDB (and
any backend) stored the vector but silently dropped the actual text —
saved memories had nothing to retrieve later. Backend.Search now also
takes the raw query text, and a failed/missing embedding no longer
hard-fails Add/Search: it degrades to a nil vector so a lexical-capable
backend can still index/find the content (Chroma has no such fallback
and now says so explicitly instead of misbehaving).

Adds pkg/rag/backends/sqlitevec: a zero-dependency backend (pure-Go
SQLite, no external service) that does cosine similarity when a real
embedding vector is available and falls back to FTS5/BM25 full-text
search otherwise. Adds pkg/rag/embeddings.OpenAICompatible, covering
both a local llama.cpp server (`--embeddings` enabled) and real OpenAI
(or any OpenAI-shaped /embeddings endpoint) through the same client.

Also fixes token usage tracking for llama.cpp streaming: the client
never requested `stream_options.include_usage` nor parsed a usage-only
SSE event, and even when present, the agent loop's RunStream dropped
any chunk with no Delta/ReasoningDelta — silently discarding the only
chunk that carries usage.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-06 00:05:30 -07:00
a38f63683b feat: add history messages, reasoning content, and adaptive language support
- Add optional history parameter to Run/RunStream for conversation context
- Add Reasoning/ReasoningDelta fields to completion and stream types
- Update llama.cpp adapter to propagate reasoning content from responses
- Default persona language now adapts to the user's language dynamically
2026-07-05 16:17:37 -07:00
1a8f1557f6 feat(llm): add ChatTemplateKwargs to CompletionRequest for provider-specific template params
- Add ChatTemplateKwargs field to llm.CompletionRequest
- Propagate kwargs through agent loop in both Run() and RunStream()
- Pass kwargs to llama.cpp client chat request
- Fix tool schema marshaling to include type/function wrapper
- Fix stream indentation logic in RunStream with responseBuilder
- Remove indirect marker from uuid dependency
2026-07-03 14:22:36 -07:00
641481022f feat(llm): add LLM client interface, types, providers (openai, llamacpp), and mock 2026-06-30 23:53:22 -07:00