Documentation
¶
Overview ¶
Package embeddedchat provides a small headless chat wrapper around the docker-agent runtime for embedders that want to drive an agent from their own UI instead of running docker-agent's Bubble Tea application.
Index ¶
- Variables
- type Config
- type Event
- type Session
- func (s *Session) Close() error
- func (s *Session) Confirm(ctx context.Context, req dagentruntime.ResumeRequest) error
- func (s *Session) Conversation() *session.Session
- func (s *Session) Restart() error
- func (s *Session) Runtime() dagentruntime.Runtime
- func (s *Session) Send(ctx context.Context, prompt string) (<-chan Event, error)
- func (s *Session) WelcomeMessage() string
- type ToolActivity
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAgentSourceRequired is returned when New is called without an agent source. ErrAgentSourceRequired = errors.New("embeddedchat: agent source is required") // ErrNotInitialized is returned when a Session has no runtime or conversation. ErrNotInitialized = errors.New("embeddedchat: session is not initialized") // ErrRunActive is returned when Send is called while a previous run is still active. ErrRunActive = errors.New("embeddedchat: a run is already active") // ErrClosed is returned when an operation is attempted after Close. ErrClosed = errors.New("embeddedchat: session is closed") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AgentSource is the agent/team definition to load. Bytes sources are a
// good fit for embedders that ship a pinned agent in their binary.
AgentSource dagentcfg.Source
// RuntimeConfig is passed to the team loader. When nil, a zero runtime
// config is used.
RuntimeConfig *dagentcfg.RuntimeConfig
// ToolsetRegistry resolves toolsets declared by AgentSource. When nil,
// docker-agent's default registry is used.
ToolsetRegistry teamloader.ToolsetRegistry
// RuntimeOptions are appended when constructing the runtime.
RuntimeOptions []dagentruntime.Opt
// SessionOptions are appended when constructing each conversation session.
SessionOptions []session.Opt
// EventBuffer controls the size of the channel returned by Send. When zero,
// a small default buffer is used.
EventBuffer int
}
Config describes an embedded agent session.
type Event ¶
type Event struct {
// Text is an assistant text delta.
Text string
// Tool describes a tool call starting, awaiting confirmation, or finishing.
Tool *ToolActivity
// Err is a user-facing runtime error.
Err error
// Done marks a clean end of the reply stream.
Done bool
// RuntimeEvent is the original docker-agent runtime event for projected
// events. Not every runtime event is forwarded by this compact API; callers
// that need the full raw stream can use Runtime().RunStream directly.
RuntimeEvent dagentruntime.Event
}
Event is the UI-friendly form of one runtime stream event.
func TranslateRuntimeEvent ¶
func TranslateRuntimeEvent(event dagentruntime.Event) (Event, bool)
TranslateRuntimeEvent translates content-bearing runtime events into the compact Event shape used by embedded chat UIs.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session owns one embedded runtime and one mutable conversation session.
func (*Session) Confirm ¶
func (s *Session) Confirm(ctx context.Context, req dagentruntime.ResumeRequest) error
Confirm answers the pending tool confirmation, if any.
func (*Session) Conversation ¶
Conversation returns the underlying docker-agent session.
The returned pointer is mutable and may be replaced by Restart. Callers that mutate it directly are responsible for coordinating with Send/Restart.
func (*Session) Restart ¶
Restart cancels any active run and replaces the conversation with a fresh session, preserving the runtime and loaded agent.
func (*Session) Runtime ¶
func (s *Session) Runtime() dagentruntime.Runtime
Runtime returns the underlying docker-agent runtime for advanced embedders. It returns nil only for sessions not created by New.
func (*Session) Send ¶
Send appends prompt to the conversation and streams the assistant reply. The returned channel closes when the runtime stream stops. A clean stream emits a final Done event first; a stream that reports an ErrorEvent emits one Err event, suppresses later projected events, then keeps draining until the runtime stops. If ctx is cancelled, Send drains the runtime stream until it stops, but no further events are delivered to the caller.
func (*Session) WelcomeMessage ¶
WelcomeMessage returns the loaded agent's welcome message.
type ToolActivity ¶
type ToolActivity struct {
Call tools.ToolCall
Def tools.Tool
Finished bool
IsError bool
// NeedsConfirmation is true when the runtime is blocked until Confirm is
// called with the user's decision.
NeedsConfirmation bool
}
ToolActivity describes one tool call surfaced by the runtime.