casebound

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package casebound hosts the case-channel agent: a Slack mention in the channel of a channel-mode Case. The turn runs as a durable agentkit process on the ReAct strategy, so this package spawns it and finishes it; Slack SDK imports are forbidden here and everything user-facing crosses the Host port as plain text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversationMessage

type ConversationMessage struct {
	UserID    string
	UserName  string
	Text      string
	Timestamp string
}

ConversationMessage is a single pre-fetched Slack message handed to the runtime. The host resolves display names; the runtime only formats.

type Host added in v0.3.0

type Host interface {
	// Reply posts the agent's answer to the thread.
	Reply(ctx context.Context, channelID, threadTS, text string) error
	// ReportFailure tells the user the turn could not finish. reason is the
	// technical cause; the host decides how much of it to show.
	ReportFailure(ctx context.Context, channelID, threadTS, reason string) error
}

Host is the Slack-facing surface a finished turn needs.

It exists because a turn no longer ends where it started: the run is a durable process, so its answer is posted from the completion handler — on whichever instance committed the terminal transition — rather than by the caller of StartTurn.

type HostFuncs added in v0.3.0

type HostFuncs struct {
	ReplyFn         func(ctx context.Context, channelID, threadTS, text string) error
	ReportFailureFn func(ctx context.Context, channelID, threadTS, reason string) error
}

HostFuncs is a struct-of-funcs adapter for tests and minimal hosts. A missing entry is an error rather than a no-op: silently dropping the answer to a mention is indistinguishable from the agent having had nothing to say.

func (HostFuncs) Reply added in v0.3.0

func (h HostFuncs) Reply(ctx context.Context, channelID, threadTS, text string) error

Reply satisfies Host.

func (HostFuncs) ReportFailure added in v0.3.0

func (h HostFuncs) ReportFailure(ctx context.Context, channelID, threadTS, reason string) error

ReportFailure satisfies Host.

type Result

type Result struct {
	Status Status
	// ProcessID names the run. Set for StatusStarted, and for StatusDuplicate
	// where it names the run the earlier delivery started.
	ProcessID agentkit.ProcessID
	// Busy describes the run holding the thread, when it could still be read.
	Busy *agentkernel.BusyTurn
}

Result is the outcome of StartTurn.

type Status

type Status int

Status discriminates what StartTurn did.

const (
	// StatusStarted means a run was spawned; its answer arrives later.
	StatusStarted Status = iota
	// StatusBusy means another turn holds this thread.
	StatusBusy
	// StatusDuplicate means this trigger already started a run; drop it
	// silently, with no Slack post.
	StatusDuplicate
)

type TurnRequest

type TurnRequest struct {
	// Session is the persisted Session for this thread. It must already exist:
	// its ID is the turn-lock subject, so the row has to be claimed before a
	// turn can be spawned.
	Session *model.Session

	ChannelID   string
	ThreadTS    string
	MentionTS   string
	MentionText string
	// MentionUserID is the Slack user who mentioned the bot. It becomes the
	// access actor for the whole run, so tools see exactly what that person may
	// see. A turn without it is refused: a run with no actor is read by the
	// usecase layer as a system context and would bypass private-case access
	// control entirely.
	MentionUserID string
	BotUserID     string

	Workspace     *model.WorkspaceEntry
	Case          *model.Case
	Actions       []*model.Action
	CurrentAction *model.Action

	// SystemMessages is the conversation snapshot inlined into the system
	// prompt; it is non-empty only for a fresh session. DeltaMessages is what
	// arrived since the previous mention.
	SystemMessages []ConversationMessage
	DeltaMessages  []ConversationMessage

	// TriggerTS is the Slack TS of the event that started this turn. It is the
	// idempotency key, which is what makes a re-delivered Slack event resolve to
	// the run it already started instead of starting a second one.
	TriggerTS string
}

TurnRequest collects what the host resolved before handing control over. The runtime never touches the Slack service: the conversation is pre-fetched and everything user-facing goes back through Host.

type UseCase

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

UseCase starts and finishes case-channel agent turns.

A turn is a durable process: StartTurn builds the prompts and spawns it, then returns. The run is driven by the agent worker one checkpointed transition at a time, and its answer is posted by onFinish.

func New

func New(repo interfaces.Repository, host Host, locator agentkernel.Locator,
	models agentkernel.ModelPolicy,
) (*UseCase, error)

New builds a casebound UseCase. locator is used only to describe the run holding a thread when a turn is refused as busy; a nil locator leaves that description empty rather than failing the turn.

func (*UseCase) Bind added in v0.3.0

func (uc *UseCase) Bind(k *agentkit.Kernel)

Bind hands over the Kernel the registered agent runs on.

func (*UseCase) Register added in v0.3.0

func (uc *UseCase) Register(reg *agentkit.Registry, limiter agentkit.Limiter, store agentkit.HistoryStore) error

Register registers the case-channel agent and wires this UseCase as its completion handler. Call it before building the Kernel, and Bind after.

func (*UseCase) StartTurn added in v0.3.0

func (uc *UseCase) StartTurn(ctx context.Context, req TurnRequest) (*Result, error)

StartTurn spawns one case-channel turn and returns as soon as the run is recorded. The LLM calls, the tool calls and the reply all happen afterwards on the agent worker.

Jump to

Keyboard shortcuts

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