reasoningbank

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinConfidence is the minimum confidence threshold for search results.
	MinConfidence = 0.7

	// ExplicitRecordConfidence is the initial confidence for explicitly recorded memories.
	ExplicitRecordConfidence = 0.8

	// DistilledConfidence is the initial confidence for distilled memories.
	DistilledConfidence = 0.6

	// DefaultSearchLimit is the default maximum number of search results.
	DefaultSearchLimit = 10
)

Variables

View Source
var (
	ErrMemoryNotFound    = errors.New("memory not found")
	ErrInvalidMemory     = errors.New("invalid memory")
	ErrEmptyTitle        = errors.New("memory title cannot be empty")
	ErrEmptyContent      = errors.New("memory content cannot be empty")
	ErrInvalidConfidence = errors.New("confidence must be between 0.0 and 1.0")
	ErrInvalidOutcome    = errors.New("outcome must be 'success' or 'failure'")
	ErrEmptyProjectID    = errors.New("project ID cannot be empty")
)

Common errors for ReasoningBank operations.

Functions

This section is empty.

Types

type Distiller

type Distiller struct {
	// contains filtered or unexported fields
}

Distiller extracts learnings from completed sessions and creates memories.

FR-006: Distillation pipeline for async memory extraction FR-009: Outcome differentiation (success vs failure)

func NewDistiller

func NewDistiller(service *Service, logger *zap.Logger) (*Distiller, error)

NewDistiller creates a new session distiller.

func (*Distiller) DistillSession

func (d *Distiller) DistillSession(ctx context.Context, summary SessionSummary) error

DistillSession extracts learnings from a completed session and creates memories.

This is called asynchronously after a session ends, so it should not block.

Success patterns (outcome="success") become positive memories. Failure patterns (outcome="failure") become anti-pattern warnings.

Initial confidence is set to DistilledConfidence (0.6) since distilled memories are less reliable than explicit captures (0.8).

type Memory

type Memory struct {
	// ID is the unique memory identifier (UUID).
	ID string `json:"id"`

	// ProjectID identifies which project this memory belongs to.
	ProjectID string `json:"project_id"`

	// Title is a brief summary of the memory (e.g., "Go error handling with context").
	Title string `json:"title"`

	// Description provides additional context about when/why this memory is useful.
	Description string `json:"description,omitempty"`

	// Content is the main memory content (strategy, anti-pattern, code example).
	Content string `json:"content"`

	// Outcome indicates if this is a success pattern or failure anti-pattern.
	Outcome Outcome `json:"outcome"`

	// Confidence is a score from 0.0 to 1.0 indicating reliability.
	// Higher confidence memories are prioritized in search results.
	// Adjusted based on feedback and usage patterns.
	Confidence float64 `json:"confidence"`

	// UsageCount tracks how many times this memory has been retrieved.
	UsageCount int `json:"usage_count"`

	// Tags are labels for categorization (e.g., "go", "error-handling", "auth").
	Tags []string `json:"tags,omitempty"`

	// CreatedAt is when the memory was created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when the memory was last modified.
	UpdatedAt time.Time `json:"updated_at"`
}

Memory represents a cross-session memory in the ReasoningBank.

Memories are distilled strategies learned from agent interactions. They can represent successful patterns (outcome="success") or anti-patterns to avoid (outcome="failure").

Confidence is tracked and adjusted based on feedback signals:

  • Explicit ratings from users
  • Implicit success (memory helped solve a task)
  • Code stability (solution didn't need rework)

func NewMemory

func NewMemory(projectID, title, content string, outcome Outcome, tags []string) (*Memory, error)

NewMemory creates a new memory with a generated UUID and default values.

func (*Memory) AdjustConfidence

func (m *Memory) AdjustConfidence(helpful bool)

AdjustConfidence updates the confidence based on feedback.

For helpful feedback:

  • Increases confidence by up to 0.1 (capped at 1.0)

For unhelpful feedback:

  • Decreases confidence by up to 0.15 (floored at 0.0)

func (*Memory) IncrementUsage

func (m *Memory) IncrementUsage()

IncrementUsage increments the usage count and updates timestamp.

func (*Memory) Validate

func (m *Memory) Validate() error

Validate checks if the memory has valid fields.

type Outcome

type Outcome string

Outcome represents the result type of a memory.

const (
	// OutcomeSuccess indicates a successful strategy or pattern.
	OutcomeSuccess Outcome = "success"

	// OutcomeFailure indicates an anti-pattern or failed approach.
	OutcomeFailure Outcome = "failure"
)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides cross-session memory storage and retrieval.

It stores memories in Qdrant using semantic search to surface relevant strategies based on similarity to the current task. Memories can be created explicitly via Record() or extracted asynchronously from sessions via the Distiller.

func NewService

func NewService(store vectorstore.Store, logger *zap.Logger) (*Service, error)

NewService creates a new ReasoningBank service.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id string) error

Delete removes a memory by ID.

func (*Service) Feedback

func (s *Service) Feedback(ctx context.Context, memoryID string, helpful bool) error

Feedback updates a memory's confidence based on user feedback.

FR-008: Feedback loop affecting confidence FR-005: Confidence tracking

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (*Memory, error)

Get retrieves a memory by ID.

This searches across all project collections to find the memory. In practice, you'd typically know the project ID, but this provides a fallback for when you only have the memory ID.

func (*Service) Record

func (s *Service) Record(ctx context.Context, memory *Memory) error

Record creates a new memory explicitly (bypasses distillation).

Sets initial confidence to ExplicitRecordConfidence (0.8) since explicit captures are more reliable than distilled ones.

FR-007: Explicit capture via memory_record FR-002: Memory schema validation

func (*Service) Search

func (s *Service) Search(ctx context.Context, projectID, query string, limit int) ([]Memory, error)

Search retrieves memories by semantic similarity to the query.

Returns memories with confidence >= MinConfidence, ordered by similarity score. Filters to only memories belonging to the specified project.

FR-003: Semantic search by similarity FR-002: Memories include required fields

type SessionOutcome

type SessionOutcome string

SessionOutcome represents the overall outcome of a session.

const (
	// SessionSuccess indicates the session achieved its goal.
	SessionSuccess SessionOutcome = "success"

	// SessionFailure indicates the session did not achieve its goal.
	SessionFailure SessionOutcome = "failure"

	// SessionPartial indicates partial success or mixed results.
	SessionPartial SessionOutcome = "partial"
)

type SessionSummary

type SessionSummary struct {
	// SessionID uniquely identifies the session.
	SessionID string

	// ProjectID identifies the project this session belongs to.
	ProjectID string

	// Outcome is the overall session result.
	Outcome SessionOutcome

	// Task is a brief description of what the session was trying to accomplish.
	Task string

	// Approach is the strategy or method used (extracted from session).
	Approach string

	// Result describes what happened (success details or failure reasons).
	Result string

	// Tags are labels for categorization (language, domain, problem type).
	Tags []string

	// Duration is how long the session lasted.
	Duration time.Duration

	// CompletedAt is when the session ended.
	CompletedAt time.Time
}

SessionSummary contains distilled information from a completed session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL