Documentation
¶
Index ¶
- Constants
- func NewSessionID() string
- type AgentMessageChunk
- type AgentSession
- func (as *AgentSession) AgentConfig() *models.AgentConfig
- func (as *AgentSession) CancelRun() bool
- func (as *AgentSession) Close() error
- func (as *AgentSession) GetID() string
- func (as *AgentSession) GetQueue() MessageQueue
- func (as *AgentSession) ID() string
- func (as *AgentSession) OwnerID() uint
- func (as *AgentSession) SendMessage(userMessage string, history []map[string]interface{}) error
- func (as *AgentSession) SetOwnerID(id uint)
- func (as *AgentSession) StartRun(userMessage string) (<-chan error, error)
- func (as *AgentSession) Stop()
- func (as *AgentSession) Transcript() []TranscriptMessage
- func (as *AgentSession) TryLockRun() bool
- func (as *AgentSession) UnlockRun()
- type MessageQueue
- type TranscriptMessage
- type TranscriptPart
Constants ¶
const ( ChunkContent = "CONTENT" ChunkToolCall = "TOOL_CALL" ChunkToolResult = "TOOL_RESULT" ChunkThinking = "THINKING" ChunkError = "ERROR" ChunkDone = "DONE" )
Chunk types as the plugin proto names them (AgentMessageChunk_ChunkType.String()).
const MetadataToolCallID = "tool_call_id"
MetadataToolCallID is the metadata key the session adds to TOOL_CALL and TOOL_RESULT chunks so consumers can pair a result with its call.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentMessageChunk ¶
type AgentMessageChunk struct {
Type string `json:"type"` // CONTENT, TOOL_CALL, TOOL_RESULT, THINKING, ERROR, DONE
Content string `json:"content"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
IsFinal bool `json:"is_final"`
}
AgentMessageChunk represents a chunk of agent response
type AgentSession ¶
type AgentSession struct {
// contains filtered or unexported fields
}
AgentSession manages the runtime lifecycle of an agent plugin conversation
func NewAgentSession ¶
func NewAgentSession( agentConfig *models.AgentConfig, pluginClient pb.PluginServiceClient, serviceBrokerID uint32, queue MessageQueue, db *gorm.DB, ) (*AgentSession, error)
NewAgentSession creates a new agent session
func NewAgentSessionWithID ¶
func NewAgentSessionWithID( id string, agentConfig *models.AgentConfig, pluginClient pb.PluginServiceClient, serviceBrokerID uint32, queue MessageQueue, db *gorm.DB, ) (*AgentSession, error)
NewAgentSessionWithID is NewAgentSession with a caller-chosen id, so the queue and the session can share one identifier.
func (*AgentSession) AgentConfig ¶
func (as *AgentSession) AgentConfig() *models.AgentConfig
AgentConfig returns the configuration the session was created for.
func (*AgentSession) CancelRun ¶
func (as *AgentSession) CancelRun() bool
CancelRun aborts the plugin stream of the active turn, if any.
func (*AgentSession) Close ¶
func (as *AgentSession) Close() error
Close closes the agent session and cleans up resources
func (*AgentSession) GetQueue ¶
func (as *AgentSession) GetQueue() MessageQueue
GetQueue returns the message queue for consuming responses
func (*AgentSession) ID ¶
func (as *AgentSession) ID() string
ID returns the session id (HubSession).
func (*AgentSession) OwnerID ¶
func (as *AgentSession) OwnerID() uint
OwnerID returns the user id the session was created for (0 if unset).
func (*AgentSession) SendMessage ¶
func (as *AgentSession) SendMessage(userMessage string, history []map[string]interface{}) error
SendMessage sends a user message to the agent plugin and streams responses back
func (*AgentSession) SetOwnerID ¶
func (as *AgentSession) SetOwnerID(id uint)
SetOwnerID records which user created the session; OwnerID reads it.
func (*AgentSession) StartRun ¶
func (as *AgentSession) StartRun(userMessage string) (<-chan error, error)
StartRun sends one user message to the plugin and streams the reply into the queue. The returned channel receives the stream's terminal error (nil on a clean end) exactly once. The history handed to the plugin is the transcript before this message.
func (*AgentSession) Stop ¶
func (as *AgentSession) Stop()
Stop closes the session (HubSession). Idempotent.
func (*AgentSession) Transcript ¶
func (as *AgentSession) Transcript() []TranscriptMessage
Transcript returns a copy of the in-memory conversation.
func (*AgentSession) TryLockRun ¶
func (as *AgentSession) TryLockRun() bool
TryLockRun claims the session for one turn; UnlockRun releases it.
func (*AgentSession) UnlockRun ¶
func (as *AgentSession) UnlockRun()
UnlockRun releases the claim taken by TryLockRun.
type MessageQueue ¶
type MessageQueue interface {
PublishStream(ctx context.Context, data []byte) error
PublishError(ctx context.Context, err error) error
ConsumeStream(ctx context.Context) <-chan []byte
ConsumeErrors(ctx context.Context) <-chan error
Close() error
}
MessageQueue is a minimal interface for publishing agent responses This avoids importing chat_session to prevent circular dependencies
type TranscriptMessage ¶
type TranscriptMessage struct {
ID string `json:"id"`
Role string `json:"role"` // user | assistant
Parts []TranscriptPart `json:"parts"`
CreatedAt time.Time `json:"created_at"`
}
TranscriptMessage is one turn of the session's in-memory transcript.
type TranscriptPart ¶
type TranscriptPart struct {
Type string `json:"type"` // text | reasoning | tool-call | data
Text string `json:"text,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
Args map[string]any `json:"args,omitempty"`
ArgsText string `json:"argsText,omitempty"`
Result any `json:"result,omitempty"`
HasResult bool `json:"-"`
IsError bool `json:"isError,omitempty"`
Name string `json:"name,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
TranscriptPart is one part of an in-memory transcript message. It mirrors the parts the v2 chat history exposes so the API can convert it directly.