agent

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateKeyFromContext

func StateKeyFromContext(ctx context.Context) (string, bool)

func WithStateKey

func WithStateKey(ctx context.Context, key string) context.Context

Types

type Agent

type Agent[T any] struct {
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent[T any](name, description string, flow *FormFlow[T], store StateReadWriter[T], options ...Option[T]) *Agent[T]

func (*Agent[T]) Description

func (a *Agent[T]) Description(ctx context.Context) string

func (*Agent[T]) Name

func (a *Agent[T]) Name(ctx context.Context) string

func (*Agent[T]) Run

func (a *Agent[T]) Run(ctx context.Context, input *adk.AgentInput, options ...adk.AgentRunOption) *adk.AsyncIterator[*adk.AgentEvent]

type Cache

type Cache[S any] interface {
	Set(ctx context.Context, key string, val S) error
	Get(ctx context.Context, key string) (S, bool, error)
	Del(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
}

type FormFlow

type FormFlow[T any] struct {
	// contains filtered or unexported fields
}

func NewFormFlow

func NewFormFlow[T any](
	spec FormSpec[T],
	patchGen patch.Generator[T],
	dialogGen dialogue.Generator[T],
	commandParser command.Parser[T],
) (*FormFlow[T], error)

func NewToolBasedFormFlow

func NewToolBasedFormFlow[T any](
	spec FormSpec[T],
	chatModel model.ToolCallingChatModel,
) (*FormFlow[T], error)

func (*FormFlow[T]) Invoke

func (a *FormFlow[T]) Invoke(ctx context.Context, input *Request[T]) (*Response[T], error)

type FormSpec

type FormSpec[T any] interface {
	JsonSchema() (string, error)

	MissingFacts(current T) []types.FieldInfo
	ValidateFacts(current T) []types.FieldInfo

	Summary(current T) string
}

type HistoryReadWriter

type HistoryReadWriter interface {
	Load(ctx context.Context) ([]*schema.Message, error)
	Save(ctx context.Context, history []*schema.Message) error
	Clear(ctx context.Context) error

	// Append loads history, appends msgs with de-duplication, trims, then saves.
	// It returns the saved history for convenient passing to adk.AgentInput.
	Append(ctx context.Context, msgs ...*schema.Message) ([]*schema.Message, error)
}

type HistoryStore

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

func NewHistoryStore

func NewHistoryStore(core Cache[[]*schema.Message], trimmer Trimmer) *HistoryStore

func NewMemoryHistoryStore

func NewMemoryHistoryStore(trimmer Trimmer) *HistoryStore

func (*HistoryStore) Append

func (s *HistoryStore) Append(ctx context.Context, msgs ...*schema.Message) ([]*schema.Message, error)

func (*HistoryStore) Clear

func (s *HistoryStore) Clear(ctx context.Context) error

func (*HistoryStore) Load

func (s *HistoryStore) Load(ctx context.Context) ([]*schema.Message, error)

func (*HistoryStore) Save

func (s *HistoryStore) Save(ctx context.Context, history []*schema.Message) error

type KeepSystemLastNTrimmer

type KeepSystemLastNTrimmer struct {
	N int
}

KeepSystemLastNTrimmer keeps all system messages and the last N non-system messages. When N <= 0, it keeps only system messages.

func (KeepSystemLastNTrimmer) Trim

func (t KeepSystemLastNTrimmer) Trim(history []*schema.Message) []*schema.Message

type MemoryCache

type MemoryCache[S any] struct {
	// contains filtered or unexported fields
}

func NewMemoryCore

func NewMemoryCore[S any]() *MemoryCache[S]

func (*MemoryCache[S]) Del

func (m *MemoryCache[S]) Del(ctx context.Context, key string) error

func (*MemoryCache[S]) Exists

func (m *MemoryCache[S]) Exists(ctx context.Context, key string) (bool, error)

func (*MemoryCache[S]) Get

func (m *MemoryCache[S]) Get(ctx context.Context, key string) (S, bool, error)

func (*MemoryCache[S]) Set

func (m *MemoryCache[S]) Set(ctx context.Context, key string, val S) error

type Option

type Option[T any] func(a *Agent[T])

type Request

type Request[T any] struct {
	State       *State[T]         `json:"state" jsonschema:"description=The current state of the form filling process"`
	ChatHistory []*schema.Message `json:"chat_history" jsonschema:"description=The chat history between the user and the agent"`
}

type Response

type Response[T any] struct {
	Message  string            `json:"message"`
	State    *State[T]         `json:"state"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type State

type State[T any] struct {
	Phase          types.Phase `` /* 145-byte string literal not displayed */
	LatestQuestion string      `json:"latest_question" jsonschema:"description=The latest question asked to the user"`
	FormState      T           `json:"form_state" jsonschema:"description=The current state of the form being filled"`
}

type StateReadWriter

type StateReadWriter[T any] interface {
	Load(ctx context.Context) (*State[T], error)
	Save(ctx context.Context, state *State[T]) error
	Clear(ctx context.Context) error
}

type StateStore

type StateStore[T any] struct {
	// contains filtered or unexported fields
}

func NewMemoryStateStore

func NewMemoryStateStore[T any](stateInit func(ctx context.Context) T) *StateStore[T]

func NewStateStore

func NewStateStore[T any](
	stateCore Cache[State[T]],
	stateInit func(ctx context.Context) T,
) *StateStore[T]

func (*StateStore[T]) Clear

func (s *StateStore[T]) Clear(ctx context.Context) error

func (*StateStore[T]) InitState

func (s *StateStore[T]) InitState(ctx context.Context) State[T]

func (*StateStore[T]) Load

func (s *StateStore[T]) Load(ctx context.Context) (*State[T], error)

func (*StateStore[T]) Save

func (s *StateStore[T]) Save(ctx context.Context, state *State[T]) error

type Store

type Store[S any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[S any](core Cache[S], namespace string, keyFn func(ctx context.Context) (string, bool)) Store[S]

func (Store[S]) Del

func (c Store[S]) Del(ctx context.Context) error

func (Store[S]) Exists

func (c Store[S]) Exists(ctx context.Context) (bool, error)

func (Store[S]) Get

func (c Store[S]) Get(ctx context.Context) (S, bool, error)

func (Store[S]) Set

func (c Store[S]) Set(ctx context.Context, val S) error

type Trimmer

type Trimmer interface {
	Trim(history []*schema.Message) []*schema.Message
}

Jump to

Keyboard shortcuts

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