241 lines
10 KiB
Go
241 lines
10 KiB
Go
// Package agent is the Agent Orchestration bounded context: the agentic
|
|
// run loop (prompt -> vLLM -> tool calls -> final reply), the chat-run
|
|
// quota/concurrency guard, and the in-flight/just-finished run registry
|
|
// that used to live in internal/handlers/chat.go's StreamManager.
|
|
//
|
|
// This is a saga coordinator, not a data owner: it holds no SQL table of
|
|
// its own. It calls billing (usage quota), conversation (persisting
|
|
// turns) and knowledge (the search_codebase tool) over gRPC, and
|
|
// workspace (every filesystem/bash tool) over gRPC, exactly replacing
|
|
// internal/llm/agent.go + internal/llm/tools.go's direct, in-process
|
|
// calls into internal/db and the local filesystem.
|
|
//
|
|
// Rendering (Markdown, syntax highlighting, deliverable cards) stays out
|
|
// of this service on purpose — see internal/render's doc comment in the
|
|
// gateway service — so this API deals in plain text and structured tool
|
|
// results, never HTML.
|
|
|
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
|
// versions:
|
|
// - protoc-gen-go-grpc v1.5.1
|
|
// - protoc v3.21.12
|
|
// source: agent/v1/agent.proto
|
|
|
|
package agentv1
|
|
|
|
import (
|
|
context "context"
|
|
grpc "google.golang.org/grpc"
|
|
codes "google.golang.org/grpc/codes"
|
|
status "google.golang.org/grpc/status"
|
|
)
|
|
|
|
// This is a compile-time assertion to ensure that this generated file
|
|
// is compatible with the grpc package it is being compiled against.
|
|
// Requires gRPC-Go v1.64.0 or later.
|
|
const _ = grpc.SupportPackageIsVersion9
|
|
|
|
const (
|
|
AgentService_StartTurn_FullMethodName = "/enkly.agent.v1.AgentService/StartTurn"
|
|
AgentService_StreamTurn_FullMethodName = "/enkly.agent.v1.AgentService/StreamTurn"
|
|
AgentService_StopTurn_FullMethodName = "/enkly.agent.v1.AgentService/StopTurn"
|
|
)
|
|
|
|
// AgentServiceClient is the client API for AgentService service.
|
|
//
|
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
|
type AgentServiceClient interface {
|
|
// StartTurn replaces the synchronous prefix of Handlers.Chat: the
|
|
// per-user throttle (ChatLimiter), the billing quota check, loading
|
|
// the conversation, persisting the user's prompt, auto-titling, and
|
|
// registering a new run (StreamManager.create) before handing off to
|
|
// a background goroutine. Returns immediately with a stream_id; the
|
|
// reply itself arrives via StreamTurn.
|
|
StartTurn(ctx context.Context, in *StartTurnRequest, opts ...grpc.CallOption) (*StartTurnResponse, error)
|
|
// StreamTurn replaces Handlers.StreamChat: a server-streaming view of
|
|
// one run's progress. resume_from_tool_index mirrors the monolith's
|
|
// SSE Last-Event-ID handling, so a reconnecting client doesn't see
|
|
// tool cards it already has.
|
|
StreamTurn(ctx context.Context, in *StreamTurnRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[TurnEvent], error)
|
|
// StopTurn replaces Handlers.StopStream.
|
|
StopTurn(ctx context.Context, in *StopTurnRequest, opts ...grpc.CallOption) (*StopTurnResponse, error)
|
|
}
|
|
|
|
type agentServiceClient struct {
|
|
cc grpc.ClientConnInterface
|
|
}
|
|
|
|
func NewAgentServiceClient(cc grpc.ClientConnInterface) AgentServiceClient {
|
|
return &agentServiceClient{cc}
|
|
}
|
|
|
|
func (c *agentServiceClient) StartTurn(ctx context.Context, in *StartTurnRequest, opts ...grpc.CallOption) (*StartTurnResponse, error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
out := new(StartTurnResponse)
|
|
err := c.cc.Invoke(ctx, AgentService_StartTurn_FullMethodName, in, out, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (c *agentServiceClient) StreamTurn(ctx context.Context, in *StreamTurnRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[TurnEvent], error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
stream, err := c.cc.NewStream(ctx, &AgentService_ServiceDesc.Streams[0], AgentService_StreamTurn_FullMethodName, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
x := &grpc.GenericClientStream[StreamTurnRequest, TurnEvent]{ClientStream: stream}
|
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := x.ClientStream.CloseSend(); err != nil {
|
|
return nil, err
|
|
}
|
|
return x, nil
|
|
}
|
|
|
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
|
type AgentService_StreamTurnClient = grpc.ServerStreamingClient[TurnEvent]
|
|
|
|
func (c *agentServiceClient) StopTurn(ctx context.Context, in *StopTurnRequest, opts ...grpc.CallOption) (*StopTurnResponse, error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
out := new(StopTurnResponse)
|
|
err := c.cc.Invoke(ctx, AgentService_StopTurn_FullMethodName, in, out, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// AgentServiceServer is the server API for AgentService service.
|
|
// All implementations must embed UnimplementedAgentServiceServer
|
|
// for forward compatibility.
|
|
type AgentServiceServer interface {
|
|
// StartTurn replaces the synchronous prefix of Handlers.Chat: the
|
|
// per-user throttle (ChatLimiter), the billing quota check, loading
|
|
// the conversation, persisting the user's prompt, auto-titling, and
|
|
// registering a new run (StreamManager.create) before handing off to
|
|
// a background goroutine. Returns immediately with a stream_id; the
|
|
// reply itself arrives via StreamTurn.
|
|
StartTurn(context.Context, *StartTurnRequest) (*StartTurnResponse, error)
|
|
// StreamTurn replaces Handlers.StreamChat: a server-streaming view of
|
|
// one run's progress. resume_from_tool_index mirrors the monolith's
|
|
// SSE Last-Event-ID handling, so a reconnecting client doesn't see
|
|
// tool cards it already has.
|
|
StreamTurn(*StreamTurnRequest, grpc.ServerStreamingServer[TurnEvent]) error
|
|
// StopTurn replaces Handlers.StopStream.
|
|
StopTurn(context.Context, *StopTurnRequest) (*StopTurnResponse, error)
|
|
mustEmbedUnimplementedAgentServiceServer()
|
|
}
|
|
|
|
// UnimplementedAgentServiceServer must be embedded to have
|
|
// forward compatible implementations.
|
|
//
|
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
|
// pointer dereference when methods are called.
|
|
type UnimplementedAgentServiceServer struct{}
|
|
|
|
func (UnimplementedAgentServiceServer) StartTurn(context.Context, *StartTurnRequest) (*StartTurnResponse, error) {
|
|
return nil, status.Errorf(codes.Unimplemented, "method StartTurn not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) StreamTurn(*StreamTurnRequest, grpc.ServerStreamingServer[TurnEvent]) error {
|
|
return status.Errorf(codes.Unimplemented, "method StreamTurn not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) StopTurn(context.Context, *StopTurnRequest) (*StopTurnResponse, error) {
|
|
return nil, status.Errorf(codes.Unimplemented, "method StopTurn not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) mustEmbedUnimplementedAgentServiceServer() {}
|
|
func (UnimplementedAgentServiceServer) testEmbeddedByValue() {}
|
|
|
|
// UnsafeAgentServiceServer may be embedded to opt out of forward compatibility for this service.
|
|
// Use of this interface is not recommended, as added methods to AgentServiceServer will
|
|
// result in compilation errors.
|
|
type UnsafeAgentServiceServer interface {
|
|
mustEmbedUnimplementedAgentServiceServer()
|
|
}
|
|
|
|
func RegisterAgentServiceServer(s grpc.ServiceRegistrar, srv AgentServiceServer) {
|
|
// If the following call pancis, it indicates UnimplementedAgentServiceServer was
|
|
// embedded by pointer and is nil. This will cause panics if an
|
|
// unimplemented method is ever invoked, so we test this at initialization
|
|
// time to prevent it from happening at runtime later due to I/O.
|
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
|
t.testEmbeddedByValue()
|
|
}
|
|
s.RegisterService(&AgentService_ServiceDesc, srv)
|
|
}
|
|
|
|
func _AgentService_StartTurn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
in := new(StartTurnRequest)
|
|
if err := dec(in); err != nil {
|
|
return nil, err
|
|
}
|
|
if interceptor == nil {
|
|
return srv.(AgentServiceServer).StartTurn(ctx, in)
|
|
}
|
|
info := &grpc.UnaryServerInfo{
|
|
Server: srv,
|
|
FullMethod: AgentService_StartTurn_FullMethodName,
|
|
}
|
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.(AgentServiceServer).StartTurn(ctx, req.(*StartTurnRequest))
|
|
}
|
|
return interceptor(ctx, in, info, handler)
|
|
}
|
|
|
|
func _AgentService_StreamTurn_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
m := new(StreamTurnRequest)
|
|
if err := stream.RecvMsg(m); err != nil {
|
|
return err
|
|
}
|
|
return srv.(AgentServiceServer).StreamTurn(m, &grpc.GenericServerStream[StreamTurnRequest, TurnEvent]{ServerStream: stream})
|
|
}
|
|
|
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
|
type AgentService_StreamTurnServer = grpc.ServerStreamingServer[TurnEvent]
|
|
|
|
func _AgentService_StopTurn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
in := new(StopTurnRequest)
|
|
if err := dec(in); err != nil {
|
|
return nil, err
|
|
}
|
|
if interceptor == nil {
|
|
return srv.(AgentServiceServer).StopTurn(ctx, in)
|
|
}
|
|
info := &grpc.UnaryServerInfo{
|
|
Server: srv,
|
|
FullMethod: AgentService_StopTurn_FullMethodName,
|
|
}
|
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.(AgentServiceServer).StopTurn(ctx, req.(*StopTurnRequest))
|
|
}
|
|
return interceptor(ctx, in, info, handler)
|
|
}
|
|
|
|
// AgentService_ServiceDesc is the grpc.ServiceDesc for AgentService service.
|
|
// It's only intended for direct use with grpc.RegisterService,
|
|
// and not to be introspected or modified (even as a copy)
|
|
var AgentService_ServiceDesc = grpc.ServiceDesc{
|
|
ServiceName: "enkly.agent.v1.AgentService",
|
|
HandlerType: (*AgentServiceServer)(nil),
|
|
Methods: []grpc.MethodDesc{
|
|
{
|
|
MethodName: "StartTurn",
|
|
Handler: _AgentService_StartTurn_Handler,
|
|
},
|
|
{
|
|
MethodName: "StopTurn",
|
|
Handler: _AgentService_StopTurn_Handler,
|
|
},
|
|
},
|
|
Streams: []grpc.StreamDesc{
|
|
{
|
|
StreamName: "StreamTurn",
|
|
Handler: _AgentService_StreamTurn_Handler,
|
|
ServerStreams: true,
|
|
},
|
|
},
|
|
Metadata: "agent/v1/agent.proto",
|
|
}
|