Skip to content

feat: add persistence, extended thinking, and observability#22

Open
urmzd wants to merge 19 commits intomainfrom
feat/persistence-thinking-otel
Open

feat: add persistence, extended thinking, and observability#22
urmzd wants to merge 19 commits intomainfrom
feat/persistence-thinking-otel

Conversation

@urmzd
Copy link
Copy Markdown
Owner

@urmzd urmzd commented Apr 4, 2026

Summary

  • Extended thinking support: Add ThinkingContent type, thinking deltas for streaming, aggregator handling, message history replay, and Anthropic provider integration
  • PostgreSQL persistence layer: New pgstore package with node, branch, and checkpoint storage backed by SQL queries and schema migrations
  • OpenTelemetry metrics: Instrument agent with request/token/tool metrics via configurable OTel provider
  • Tree serialization: Add Serialize and FromStore for tree persistence and reconstruction
  • Build/docs: Settable version at build time, compiled binary, updated README and llms.txt

Test plan

  • Verify thinking content flows end-to-end with Anthropic extended thinking enabled
  • Run delta_test.go for updated type count
  • Stand up PostgreSQL and validate pgstore CRUD operations via migrations
  • Confirm OTel metrics export with a local collector
  • Smoke test the compiled saige binary

urmzd added 19 commits April 4, 2026 00:47
Add ThinkingContent type to represent extended thinking blocks from LLM providers. Includes an opaque Signature field required for multi-turn round-trips with providers that support thinking (e.g. Anthropic).
Add ThinkingStartDelta, ThinkingContentDelta, and ThinkingEndDelta types to support streaming extended thinking blocks from LLM providers. These deltas complete the delta type hierarchy used for event streaming.
Update DefaultAggregator to accumulate thinking deltas into complete ThinkingContent blocks. Track thinking state alongside existing text and tool state machine.
Update Replay function to reconstruct thinking deltas when replaying AssistantMessages containing ThinkingContent blocks. Maintains message history semantics for consumers.
Implement extended thinking support in Anthropic adapter. Add WithThinking option to enable thinking with token budget. Parse thinking deltas from stream and preserve thinking signature for multi-turn conversations.
Implement metrics collection using OpenTelemetry. Track token usage, tool execution duration, LLM call duration, and agent invocation duration. Provides observability hooks for production deployments.
Implement agent store backed by PostgreSQL with pgx. Persists nodes, branches, checkpoints, and embeddings. Includes SQL schemas for tree nodes with parent-child relationships, branching state, and conversation checkpoints.
Implement tree serialization for persistence and transmission. Converts between in-memory tree structure and wire format compatible with storage backends.
Add FromStore constructor to rebuild Tree instances from persisted data. Reconstructs node maps, parent-child relationships, branches, and checkpoints from loaded data.
Change version from const to var initialized to 'dev'. Enables setting version via -ldflags at build time for release binaries.
Update delta type tests to account for three new thinking delta types. Verify all 17 delta types satisfy the Delta interface.
Update go.mod with OpenTelemetry metric, trace, and core dependencies. Add transitive dependencies for observability instrumentation.
Document extended thinking support in message table. Add note on Anthropic lacking embedding API and guide users to supply separate embedder from another provider. Update delta table to include three thinking delta types.
Add PostgreSQL migration template with node tree structure, branch tracking, and checkpoint tables. Supports hierarchical conversation storage with pgvector embeddings.
Expand llms.txt description to cover new features: extended thinking, conversation tree branching, tree serialization, structured output, provider resilience, and evaluation framework. Update key files index to reflect new agent/tree and eval packages.
Add compiled saige CLI executable.
Add nolint:gosec comments to version type conversions in the pgstore node module. The version values are guaranteed to fit within int64 range (stored in DB as int64, always non-negative), so these security linting warnings can be safely suppressed.
Tighten file permissions for created directories and JSON files to reduce unnecessary access (0o755 -> 0o750, 0o644 -> 0o600). Additionally, sanitize file paths before reading with filepath.Clean to prevent directory traversal attacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant