nmemory

package
v0.0.0-...-110f058 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package nmemory provides the Memory node implementation for flow execution. Memory nodes are passive configuration providers that supply conversation history to connected AI Agent nodes via HandleAiMemory edges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Role    string // "user", "assistant", "system"
	Content string
}

Message represents a single message in the conversation history.

type NodeMemory

type NodeMemory struct {
	FlowNodeID idwrap.IDWrap
	Name       string
	MemoryType mflow.AiMemoryType
	WindowSize int32

	Messages []Message
	// contains filtered or unexported fields
}

NodeMemory represents a Memory node that provides conversation history to AI Agent nodes. It is a passive node - it does not execute but provides and manages conversation memory when discovered by AI nodes via HandleAiMemory edges.

func New

func New(
	id idwrap.IDWrap,
	name string,
	memoryType mflow.AiMemoryType,
	windowSize int32,
) *NodeMemory

New creates a new NodeMemory with the given configuration. For WindowBuffer memory type, windowSize must be at least 1. Invalid windowSize values are automatically corrected to a minimum of 1.

func (*NodeMemory) AddMessage

func (n *NodeMemory) AddMessage(role, content string)

AddMessage appends a message to the conversation history. For WindowBuffer memory type, it enforces the window size limit by removing the oldest messages when the limit is exceeded.

func (*NodeMemory) Clear

func (n *NodeMemory) Clear()

Clear resets the conversation history.

func (*NodeMemory) GetID

func (n *NodeMemory) GetID() idwrap.IDWrap

GetID returns the node's unique identifier.

func (*NodeMemory) GetMessages

func (n *NodeMemory) GetMessages() []Message

GetMessages returns a copy of the current conversation history. Returns a copy to prevent concurrent modification issues.

func (*NodeMemory) GetName

func (n *NodeMemory) GetName() string

GetName returns the node's display name.

func (*NodeMemory) Len

func (n *NodeMemory) Len() int

Len returns the current number of messages in the history.

func (*NodeMemory) RunAsync

func (n *NodeMemory) RunAsync(ctx context.Context, req *node.FlowNodeRequest, resultChan chan node.FlowNodeResult)

RunAsync runs the node asynchronously by calling RunSync and sending the result.

func (*NodeMemory) RunSync

RunSync is a no-op for Memory nodes. Memory nodes are passive state containers and do not execute directly. They are discovered by AI Agent nodes via HandleAiMemory edges.

Jump to

Keyboard shortcuts

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