agent

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ToolErrorPrefix = "tool execution failed: "

ToolErrorPrefix marks a tool result that carries a failure. The UI shows such a result as a failed call instead of a successful one.

Variables

This section is empty.

Functions

func ApplySkill added in v0.7.0

func ApplySkill(ac *config.Agent, sk config.Skill)

ApplySkill folds a skill into an agent configuration: the skill's instructions go in front of the agent's system prompt and its extension tools are added without duplicating tools the agent already has.

This is the eager half of the Agent Skills model: an explicitly activated skill (`/skill`, session config options) is inlined for the whole session. Skills that are only discovered stay out of the prompt body; see skillsCatalog.

func IsToolError

func IsToolError(result string) bool

IsToolError reports whether a tool result carries a failure.

Types

type Agent

type Agent interface {
	// Run runs the agent
	Run(prompt string) error
	// Chat performs conversation, returns response content
	Chat(ctx context.Context, history []*schema.Message, prompt string) (string, error)
	// ChatWithCallback performs conversation, supporting tool call callbacks
	ChatWithCallback(ctx context.Context, history []*schema.Message, prompt string, callback func(interface{})) (string, error)
	// ChatStream performs streaming conversation, handles streaming output through chunk callback
	ChatStream(ctx context.Context, history []*schema.Message, prompt string, chunkCallback func(*StreamChunk), toolCallback func(interface{})) error
}

Agent defines the agent interface used in the CLI.

The conversation methods take the prior turns (history) explicitly: the underlying ReAct flow is stateless, so multi-turn context is passed in by the caller on every turn.

type Factory

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

Factory is used to create Agent instances

func NewFactory

func NewFactory(cfg *config.Config) *Factory

NewFactory creates a new Factory

func (*Factory) CreateAgent

func (f *Factory) CreateAgent(name string) (Agent, error)

CreateAgent creates Agent based on name

func (*Factory) WithModel added in v0.4.0

func (f *Factory) WithModel(model string) *Factory

WithModel pins the model used by agents created afterwards. The ACP service uses it to honor session/set_config_option model switches.

func (*Factory) WithSkill added in v0.4.0

func (f *Factory) WithSkill(skill string) *Factory

WithSkill activates a configured skill for created agents.

type ReactAgent

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

ReactAgent implements Agent using React pattern from cloudwego/eino library

func NewReactAgent

func NewReactAgent(agentName string, cfg *config.Agent) *ReactAgent

NewReactAgent creates a new ReactAgent

func (*ReactAgent) Chat

func (r *ReactAgent) Chat(ctx context.Context, history []*schema.Message, prompt string) (output string, retErr error)

Chat performs conversation, returns response content

func (*ReactAgent) ChatStream

func (r *ReactAgent) ChatStream(ctx context.Context, history []*schema.Message, prompt string, chunkCallback func(*StreamChunk), toolCallback func(interface{})) (retErr error)

ChatStream performs streaming conversation, handles streaming output via chunk callback

func (*ReactAgent) ChatWithCallback

func (r *ReactAgent) ChatWithCallback(ctx context.Context, history []*schema.Message, prompt string, callback func(interface{})) (output string, retErr error)

ChatWithCallback performs conversation with streaming output and callback support

func (*ReactAgent) Init

func (r *ReactAgent) Init() error

Init initializes Agent

func (*ReactAgent) Run

func (r *ReactAgent) Run(prompt string) error

Run runs Agent with optimized output formatting

type StreamChunk

type StreamChunk struct {
	Content string
	Type    string // "content", "reasoning", "tool_start", "tool_end", "error"
	Tool    string // Tool name (only used for tool-related messages)
}

StreamChunk represents a data chunk for streaming output

type ThinkFilter

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

ThinkFilter splits streamed content into visible answer text and reasoning text. Markers may span chunk boundaries; partial markers are buffered until they can be classified.

func NewThinkFilter

func NewThinkFilter() *ThinkFilter

NewThinkFilter creates a filter state for one streaming turn.

func (*ThinkFilter) Feed

func (f *ThinkFilter) Feed(s string) (visible, thought string)

Feed processes one chunk and returns the visible answer content and the reasoning content extracted from it (either may be empty).

func (*ThinkFilter) Flush

func (f *ThinkFilter) Flush() (visible, thought string)

Flush drains any buffered content when the stream ends. An unterminated thinking section is returned as reasoning rather than dropped.

type ToolCallCallback

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

ToolCallCallback custom callback handler for capturing tool call information

func (*ToolCallCallback) OnEnd

OnEnd callback when node ends

func (*ToolCallCallback) OnEndWithStreamOutput

OnEndWithStreamOutput callback when stream output ends

func (*ToolCallCallback) OnError

func (t *ToolCallCallback) OnError(ctx context.Context, info *callbacks.RunInfo, err error) context.Context

OnError callback when node encounters error

func (*ToolCallCallback) OnStart

OnStart callback when node starts

func (*ToolCallCallback) OnStartWithStreamInput

OnStartWithStreamInput callback when stream input starts

type ToolCallInfo

type ToolCallInfo struct {
	Type      string // "start", "end", "error"
	Name      string
	CallID    string // eino tool call id: pairs a call with its result
	Arguments string
	Result    string
	Error     string
}

ToolCallInfo represents structured tool call information

Jump to

Keyboard shortcuts

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