-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagents.go
More file actions
72 lines (65 loc) · 2.08 KB
/
agents.go
File metadata and controls
72 lines (65 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cursor
import (
"context"
"fmt"
"net/url"
)
// LaunchAgent starts a new background agent.
func (c *Client) LaunchAgent(ctx context.Context, req LaunchRequest) (*Agent, error) {
var out Agent
if err := c.do(ctx, "POST", "/v0/agents", nil, req, &out); err != nil {
return nil, err
}
return &out, nil
}
// AddFollowup sends additional instructions to a running agent.
func (c *Client) AddFollowup(ctx context.Context, id string, req FollowupRequest) (string, error) {
var out FollowupResponse
path := fmt.Sprintf("/v0/agents/%s/followup", url.PathEscape(id))
if err := c.do(ctx, "POST", path, nil, req, &out); err != nil {
return "", err
}
return out.ID, nil
}
// GetAgent retrieves the current status of an agent.
func (c *Client) GetAgent(ctx context.Context, id string) (*Agent, error) {
var out Agent
path := fmt.Sprintf("/v0/agents/%s", url.PathEscape(id))
if err := c.do(ctx, "GET", path, nil, nil, &out); err != nil {
return nil, err
}
return &out, nil
}
// ListAgents retrieves multiple agents with optional pagination.
func (c *Client) ListAgents(ctx context.Context, limit int, cursor *string) (*ListAgentsResponse, error) {
q := url.Values{}
if limit > 0 {
q.Set("limit", fmt.Sprintf("%d", limit))
}
if cursor != nil && *cursor != "" {
q.Set("cursor", *cursor)
}
var out ListAgentsResponse
if err := c.do(ctx, "GET", "/v0/agents", q, nil, &out); err != nil {
return nil, err
}
return &out, nil
}
// DeleteAgent terminates and deletes an agent.
func (c *Client) DeleteAgent(ctx context.Context, id string) (string, error) {
var out DeleteResponse
path := fmt.Sprintf("/v0/agents/%s", url.PathEscape(id))
if err := c.do(ctx, "DELETE", path, nil, nil, &out); err != nil {
return "", err
}
return out.ID, nil
}
// GetConversation returns the conversation history for an agent.
func (c *Client) GetConversation(ctx context.Context, id string) (*Conversation, error) {
var out Conversation
path := fmt.Sprintf("/v0/agents/%s/conversation", url.PathEscape(id))
if err := c.do(ctx, "GET", path, nil, nil, &out); err != nil {
return nil, err
}
return &out, nil
}