Documentation
¶
Overview ¶
Package executor provides remote tool execution capabilities. It enables running tools in isolated containers while the LLM orchestration happens in the main backend.
Index ¶
- func MarshalRequest(req tool.Request) ([]byte, error)
- func UnmarshalResponse(data []byte) (tool.Response, error)
- type RemoteExecutor
- type ToolServer
- type Transport
- type WSTransport
- func (t *WSTransport) Close() error
- func (t *WSTransport) FetchTools(ctx context.Context) ([]tool.Info, error)
- func (t *WSTransport) PushAnswers(ctx context.Context, answers [][]string) error
- func (t *WSTransport) Send(ctx context.Context, req tool.Request) (tool.Response, error)
- func (t *WSTransport) SetActiveTools(ctx context.Context, toolNames []string) error
- func (t *WSTransport) SetRules(ctx context.Context, rules []bus.PermissionRule) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalRequest ¶
MarshalRequest serializes a tool request to JSON.
Types ¶
type RemoteExecutor ¶
type RemoteExecutor struct {
// contains filtered or unexported fields
}
RemoteExecutor implements tool.Executor by forwarding requests over a Transport to a remote ToolServer.
func NewRemoteExecutor ¶
func NewRemoteExecutor(transport Transport, tools []tool.Info) *RemoteExecutor
NewRemoteExecutor creates a RemoteExecutor with the given transport and tool definitions. The tools parameter provides the tool schemas that the LLM needs to see.
func (*RemoteExecutor) Close ¶
func (e *RemoteExecutor) Close() error
Close closes the underlying transport.
func (*RemoteExecutor) Execute ¶
Execute implements tool.Executor by sending the request over the transport.
func (*RemoteExecutor) Tools ¶
func (e *RemoteExecutor) Tools() []tool.Info
Tools implements tool.Executor by returning the cached tool definitions.
type ToolServer ¶
type ToolServer struct {
// contains filtered or unexported fields
}
ToolServer wraps a tool.Executor and serves requests over WebSocket. It runs in the container and executes tools locally. It owns a Bus, PermissionManager, and QuestionManager so that tools executing inside the container can call AskPermission/AskQuestion.
func NewToolServer ¶
func NewToolServer(executor tool.Executor) *ToolServer
NewToolServer creates a ToolServer with the given executor.
func (*ToolServer) Handler ¶
func (s *ToolServer) Handler() http.Handler
Handler returns an http.Handler for the WebSocket endpoint.
func (*ToolServer) ListenAndServe ¶
func (s *ToolServer) ListenAndServe(addr string) error
ListenAndServe starts the server on the given address.
func (*ToolServer) PermissionManager ¶
func (s *ToolServer) PermissionManager() *bus.PermissionManager
PermissionManager returns the server's permission manager.
func (*ToolServer) QuestionManager ¶
func (s *ToolServer) QuestionManager() *bus.QuestionManager
QuestionManager returns the server's question manager.
func (*ToolServer) ServeHTTP ¶
func (s *ToolServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for easy integration.
type Transport ¶
type Transport interface {
// Send sends a tool request and waits for the response.
Send(ctx context.Context, req tool.Request) (tool.Response, error)
// Close closes the transport connection.
Close() error
}
Transport abstracts the communication layer between RemoteExecutor and ToolServer. Implementations can use WebSocket, HTTP, gRPC, or any other protocol.
type WSTransport ¶
type WSTransport struct {
// contains filtered or unexported fields
}
WSTransport implements Transport using WebSocket.
func NewWSTransport ¶
func NewWSTransport(url string, headers ...http.Header) (*WSTransport, error)
NewWSTransport creates a WebSocket transport by connecting to the given URL. The URL should be in the format "ws://host:port/ws". Optional headers are sent during the handshake (e.g., Authorization).
func NewWSTransportFromConn ¶
func NewWSTransportFromConn(conn *websocket.Conn) *WSTransport
NewWSTransportFromConn creates a WebSocket transport from an existing connection. This is useful when the connection is established by the caller.
func (*WSTransport) FetchTools ¶
FetchTools requests the tool definitions from the remote server.
func (*WSTransport) PushAnswers ¶
func (t *WSTransport) PushAnswers(ctx context.Context, answers [][]string) error
PushAnswers sends pre-loaded answers to the remote ToolServer and waits for ack.
func (*WSTransport) SetActiveTools ¶
func (t *WSTransport) SetActiveTools(ctx context.Context, toolNames []string) error
SetActiveTools tells the remote ToolServer which tools to expose and accept.
func (*WSTransport) SetRules ¶
func (t *WSTransport) SetRules(ctx context.Context, rules []bus.PermissionRule) error
SetRules sends permission rules to the remote ToolServer and waits for ack.