agent

package
v1.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSystemPrompt

func BuildSystemPrompt(workspaceDir string, files []string) (string, error)

func CreateAgent

func CreateAgent(
	ctx context.Context, cfg Config, systemPrompt string,
	tools []fantasy.AgentTool, logger *zap.Logger,
) (fantasy.Agent, fantasy.LanguageModel, error)

Types

type Config

type Config struct {
	Provider      string
	ModelName     string
	APIKey        string
	APIBase       string
	MaxTokens     int
	MaxIterations int
}

type Service

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

func NewService

func NewService(
	agent fantasy.Agent, model fantasy.LanguageModel,
	store *memory.Store, compactor *memory.Compactor, logger *zap.Logger,
) *Service

func (*Service) Chat

func (s *Service) Chat(ctx context.Context, sessionID, prompt string) (string, error)

func (*Service) ChatStream

func (s *Service) ChatStream(
	ctx context.Context, sessionID, prompt string, cb StreamCallback,
) (string, error)

func (*Service) DeleteSession

func (s *Service) DeleteSession(ctx context.Context, sessionID string) error

func (*Service) ListSessionMessages

func (s *Service) ListSessionMessages(ctx context.Context, sessionID string, _ int) ([]SessionMessage, error)

ListSessionMessages returns the recent messages stored for sessionID in role/content form suitable for gRPC transport. limit <= 0 means "use the store default" (LIMIT 50 today).

func (*Service) ListSessions

func (s *Service) ListSessions(ctx context.Context) ([]memory.SessionInfo, error)

func (*Service) PromptObject

func (s *Service) PromptObject(
	ctx context.Context,
	prompt string, schemaJSON []byte, schemaName, schemaDesc string,
) ([]byte, string, error)

PromptObject runs a one-shot, stateless structured-output query against the underlying LanguageModel. No session memory is loaded or saved, no tool loop is run — just prompt + schema in, parsed object out. Matches fantasy.LanguageModel.GenerateObject one-to-one and exists so the runtime's gRPC surface has a place to hang the call without exposing the model type through Service's public API.

schemaJSON must be a JSON Schema document that unmarshals into fantasy/schema.Schema (common subset: type, properties, required, items, enum, format, min/max). schemaName and schemaDesc surface in tool-mode providers as the synthetic tool's name/description.

ObjectMode (JSON / tool / text / auto) is provider-level — set when the LanguageModel is constructed via e.g. anthropic.WithObjectMode(...). This method doesn't override it per-call because fantasy.ObjectCall has no per-call mode field.

Returns (objectJSON, rawText). rawText is the model's unparsed reply — useful for debugging when repair was needed.

type SessionMessage

type SessionMessage struct {
	Role      string
	Content   string
	CreatedAt int64
}

SessionMessage is the plain wire-ready view of a stored chat message: role, text, and its creation time. Compacted or summarised entries already flow through the store as role=assistant, so callers get a post-compaction view.

type StreamCallback

type StreamCallback func(event StreamEvent)

type StreamEvent

type StreamEvent struct {
	Type     string
	Step     int
	ToolName string
	ToolID   string
	Content  string
}

Jump to

Keyboard shortcuts

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