Documentation
¶
Overview ¶
Package bridge provides agent-to-agent communication via JSONL files.
Index ¶
- type Bridge
- func (b *Bridge) Close() error
- func (b *Bridge) Drain(ctx context.Context, target string, seenIDs map[string]bool) ([]*Message, error)
- func (b *Bridge) DrainNew(ctx context.Context, target string, sinceID string) ([]*Message, error)
- func (b *Bridge) GetByID(id string) (*Message, error)
- func (b *Bridge) Open() error
- func (b *Bridge) Send(ctx context.Context, msg *Message) (bool, error)
- func (b *Bridge) SetLogger(log *slog.Logger)
- func (b *Bridge) Status() *Status
- type Message
- func NewMessage(msgType MessageType, from, to, content string) *Message
- func NewResultMessage(from, to, result string) *Message
- func NewReviewMessage(from, to, review string) *Message
- func NewSignalMessage(from string, signal Signal, content string) *Message
- func NewTaskMessage(from, to, task string) *Message
- type MessageType
- type Server
- type Signal
- type Status
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge handles message passing between agents with SHA256 deduplication.
func (*Bridge) Drain ¶
func (b *Bridge) Drain(ctx context.Context, target string, seenIDs map[string]bool) ([]*Message, error)
Drain retrieves all unprocessed messages for a target agent. Messages are marked as seen to prevent re-delivery.
func (*Bridge) Send ¶
Send sends a message through the bridge. Returns false if the message is a duplicate.
type Message ¶
type Message struct {
// ID is the unique SHA256 hash of the message content.
ID string `json:"id"`
// Type categorizes the message.
Type MessageType `json:"type"`
// From identifies the sender agent.
From string `json:"from"`
// To identifies the target agent (empty for broadcast).
To string `json:"to,omitempty"`
// Content is the message payload.
Content string `json:"content"`
// Signal is set for signal-type messages.
Signal Signal `json:"signal,omitempty"`
// Metadata contains optional key-value data.
Metadata map[string]any `json:"metadata,omitempty"`
// Timestamp is when the message was created.
Timestamp time.Time `json:"timestamp"`
// RunID identifies the run this message belongs to.
RunID int `json:"run_id"`
// Iteration is the loop iteration number.
Iteration int `json:"iteration"`
}
Message represents a message passed between agents via the bridge.
func NewMessage ¶
func NewMessage(msgType MessageType, from, to, content string) *Message
NewMessage creates a new message with auto-generated ID.
func NewResultMessage ¶
NewResultMessage creates a result message.
func NewReviewMessage ¶
NewReviewMessage creates a review request/response message.
func NewSignalMessage ¶
NewSignalMessage creates a signal message.
func NewTaskMessage ¶
NewTaskMessage creates a task assignment message.
func (*Message) IsDoneSignal ¶
IsDoneSignal returns true if this is a DONE signal.
func (*Message) IsFailSignal ¶
IsFailSignal returns true if this is a FAIL signal.
func (*Message) IsForAgent ¶
IsForAgent returns true if this message is targeted at the specified agent.
func (*Message) IsPassSignal ¶
IsPassSignal returns true if this is a PASS signal.
func (*Message) WithMetadata ¶
WithMetadata adds metadata to the message and returns it for chaining.
func (*Message) WithRunInfo ¶
WithRunInfo sets run ID and iteration and returns it for chaining.
type MessageType ¶
type MessageType string
MessageType represents the type of bridge message.
const ( // TypeTask indicates a task assignment message. TypeTask MessageType = "task" // TypeResult indicates a task result message. TypeResult MessageType = "result" // TypeReview indicates a review request/response. TypeReview MessageType = "review" // TypeSignal indicates a control signal (e.g., DONE, PASS, FAIL). TypeSignal MessageType = "signal" // TypeChat indicates a general chat/context message. TypeChat MessageType = "chat" )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an MCP server that exposes bridge tools to agents.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server on the given address. Use "stdio" for stdin/stdout transport, or a TCP address like ":0" for socket.
type Status ¶
type Status struct {
TotalMessages int
ByAgent map[string]int
ByType map[MessageType]int
HasDoneSignal bool
PassCount int
FailCount int
}
Status contains bridge status information.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage handles persistent storage of bridge messages in JSONL format.
func NewStorage ¶
NewStorage creates a new storage instance for the given file path.