Skip to content

Commit 3db41c1

Browse files
committed

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

polycode/client.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ type StartAppRequest struct {
3030
}
3131

3232
type ExecServiceRequest struct {
33-
EnvId string `json:"envId"`
34-
Service string `json:"service"`
35-
TenantId string `json:"tenantId"`
36-
PartitionKey string `json:"partitionKey"`
37-
Method string `json:"method"`
38-
Options TaskOptions `json:"options"`
39-
FireAndForget bool `json:"fireAndForget"`
40-
Input any `json:"input"`
33+
EnvId string `json:"envId"`
34+
Service string `json:"service"`
35+
TenantId string `json:"tenantId"`
36+
PartitionKey string `json:"partitionKey"`
37+
Method string `json:"method"`
38+
Options TaskOptions `json:"options"`
39+
FireAndForget bool `json:"fireAndForget"`
40+
Headers map[string]string `json:"headers"`
41+
Input any `json:"input"`
4142
}
4243

4344
type ExecAppRequest struct {

polycode/context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ type ServiceContext interface {
2828
type WorkflowContext interface {
2929
BaseContext
3030
Service(service string) *RemoteServiceBuilder
31+
Agent(agent string) *RemoteAgentBuilder
3132
ServiceEx(envId string, service string) *RemoteServiceBuilder
33+
AgentEx(envId string, agent string) *RemoteAgentBuilder
3234
App(appName string) RemoteApp
3335
AppEx(envId string, appName string) RemoteApp
3436
Controller(controller string) RemoteController
@@ -107,12 +109,24 @@ func (s ContextImpl) Service(service string) *RemoteServiceBuilder {
107109
}
108110
}
109111

112+
func (s ContextImpl) Agent(agent string) *RemoteAgentBuilder {
113+
return &RemoteAgentBuilder{
114+
ctx: s.ctx, sessionId: s.sessionId, agent: agent, serviceClient: s.serviceClient,
115+
}
116+
}
117+
110118
func (s ContextImpl) ServiceEx(envId string, service string) *RemoteServiceBuilder {
111119
return &RemoteServiceBuilder{
112120
ctx: s.ctx, sessionId: s.sessionId, envId: envId, service: service, serviceClient: s.serviceClient,
113121
}
114122
}
115123

124+
func (s ContextImpl) AgentEx(envId string, agent string) *RemoteAgentBuilder {
125+
return &RemoteAgentBuilder{
126+
ctx: s.ctx, sessionId: s.sessionId, envId: envId, agent: agent, serviceClient: s.serviceClient,
127+
}
128+
}
129+
116130
func (s ContextImpl) App(appName string) RemoteApp {
117131
return RemoteApp{
118132
ctx: s.ctx, sessionId: s.sessionId, appName: appName, serviceClient: s.serviceClient,

polycode/model.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"time"
55
)
66

7+
const AgentNameHeader = "X-Sidecar-Agent-Name"
8+
79
type BackoffStrategy struct {
810
InitialInterval time.Duration `json:"initialInterval"`
911
MaxInterval time.Duration `json:"maxInterval"`
@@ -136,3 +138,19 @@ type CallerContextMeta struct {
136138
TaskName string `json:"taskName"`
137139
TaskId string `json:"taskId"`
138140
}
141+
142+
type AgentInput struct {
143+
SessionKey string `json:"sessionKey"`
144+
LLMInput LLMInput `json:"llmInput"`
145+
Labels map[string]string `json:"labels"`
146+
}
147+
148+
type LLMInput struct {
149+
Text string `json:"text"`
150+
//Files []File `json:"files"`
151+
}
152+
153+
//type File struct {
154+
// Data []byte `json:"data"`
155+
// Path string `json:"path"`
156+
//}

polycode/service.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,72 @@ func (r RemoteService) Send(options TaskOptions, method string, input any) error
132132
}
133133
}
134134

135+
type RemoteAgentBuilder struct {
136+
ctx context.Context
137+
sessionId string
138+
envId string
139+
agent string
140+
serviceClient *ServiceClient
141+
tenantId string
142+
}
143+
144+
func (r *RemoteAgentBuilder) WithTenantId(tenantId string) *RemoteAgentBuilder {
145+
r.tenantId = tenantId
146+
return r
147+
}
148+
149+
func (r *RemoteAgentBuilder) Get() RemoteAgent {
150+
return RemoteAgent{
151+
ctx: r.ctx,
152+
sessionId: r.sessionId,
153+
envId: r.envId,
154+
agent: r.agent,
155+
serviceClient: r.serviceClient,
156+
tenantId: r.tenantId,
157+
}
158+
}
159+
160+
type RemoteAgent struct {
161+
ctx context.Context
162+
sessionId string
163+
envId string
164+
agent string
165+
serviceClient *ServiceClient
166+
tenantId string
167+
}
168+
169+
func (r RemoteAgent) Call(options TaskOptions, input AgentInput) Response {
170+
req := ExecServiceRequest{
171+
EnvId: r.envId,
172+
Service: "agent_service",
173+
TenantId: r.tenantId,
174+
PartitionKey: r.agent + ":" + input.SessionKey,
175+
Method: "CallAgent",
176+
Options: options,
177+
Headers: map[string]string{
178+
AgentNameHeader: r.agent,
179+
},
180+
Input: input,
181+
}
182+
183+
output, err := r.serviceClient.ExecService(r.sessionId, req)
184+
if err != nil {
185+
fmt.Printf("client: exec task error: %v\n", err)
186+
return Response{
187+
output: nil,
188+
isError: true,
189+
error: ErrTaskExecError.Wrap(err),
190+
}
191+
}
192+
193+
fmt.Printf("client: exec task output: %v\n", output)
194+
return Response{
195+
output: output.Output,
196+
isError: output.IsError,
197+
error: output.Error,
198+
}
199+
}
200+
135201
type RemoteApp struct {
136202
ctx context.Context
137203
sessionId string

0 commit comments

Comments
 (0)