Skip to content

Commit b46fb82

Browse files
feat: add filters to count_agents endpoint [LET-5380] [LET-5497]
1 parent 2ae116f commit b46fb82

File tree

7 files changed

+90
-6
lines changed

7 files changed

+90
-6
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 116
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/letta-ai%2Fletta-sdk-5db911b088119948c6ff8eb328caa30a5085ce2e217bf139aa654d5fa602f642.yml
3-
openapi_spec_hash: 6de73deeb221b0e3fd8b60d73b2d2e12
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/letta-ai%2Fletta-sdk-779ee7a7a34dc46d2e6b71e0c87eb3b31520e439b27542a8b40963480ad63f74.yml
3+
openapi_spec_hash: d03e9b957df56ce2ea87653feb9bdb6a
44
config_hash: 436e42e127dea74b3004397fffda6f99

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Methods:
120120
- <code title="get /v1/agents/{agent_id}">client.agents.<a href="./src/resources/agents/agents.ts">retrieve</a>(agentID, { ...params }) -> AgentState</code>
121121
- <code title="get /v1/agents/">client.agents.<a href="./src/resources/agents/agents.ts">list</a>({ ...params }) -> AgentStatesArrayPage</code>
122122
- <code title="delete /v1/agents/{agent_id}">client.agents.<a href="./src/resources/agents/agents.ts">delete</a>(agentID) -> unknown</code>
123-
- <code title="get /v1/agents/count">client.agents.<a href="./src/resources/agents/agents.ts">count</a>() -> AgentCountResponse</code>
123+
- <code title="get /v1/agents/count">client.agents.<a href="./src/resources/agents/agents.ts">count</a>({ ...params }) -> AgentCountResponse</code>
124124
- <code title="get /v1/agents/{agent_id}/export">client.agents.<a href="./src/resources/agents/agents.ts">exportFile</a>(agentID, { ...params }) -> string</code>
125125
- <code title="post /v1/agents/import">client.agents.<a href="./src/resources/agents/agents.ts">importFile</a>({ ...params }) -> AgentImportFileResponse</code>
126126
- <code title="patch /v1/agents/{agent_id}">client.agents.<a href="./src/resources/agents/agents.ts">modify</a>(agentID, { ...params }) -> AgentState</code>

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
ToolsArrayPage,
5959
} from './resources/tools';
6060
import {
61+
AgentCountParams,
6162
AgentCountResponse,
6263
AgentCreateParams,
6364
AgentDeleteResponse,
@@ -1046,6 +1047,7 @@ export declare namespace Letta {
10461047
type AgentCreateParams as AgentCreateParams,
10471048
type AgentRetrieveParams as AgentRetrieveParams,
10481049
type AgentListParams as AgentListParams,
1050+
type AgentCountParams as AgentCountParams,
10491051
type AgentExportFileParams as AgentExportFileParams,
10501052
type AgentImportFileParams as AgentImportFileParams,
10511053
type AgentModifyParams as AgentModifyParams,

src/resources/agents/agents.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,14 @@ export class Agents extends APIResource {
149149
}
150150

151151
/**
152-
* Get the total number of agents.
152+
* Get the total number of agents with optional filtering. Supports the same
153+
* filters as list_agents for consistent querying.
153154
*/
154-
count(options?: RequestOptions): APIPromise<AgentCountResponse> {
155-
return this._client.get('/v1/agents/count', options);
155+
count(
156+
query: AgentCountParams | null | undefined = {},
157+
options?: RequestOptions,
158+
): APIPromise<AgentCountResponse> {
159+
return this._client.get('/v1/agents/count', { query, ...options });
156160
}
157161

158162
/**
@@ -1491,6 +1495,59 @@ export interface AgentListParams extends ArrayPageParams {
14911495
template_id?: string | null;
14921496
}
14931497

1498+
export interface AgentCountParams {
1499+
/**
1500+
* Search agents by base template ID
1501+
*/
1502+
base_template_id?: string | null;
1503+
1504+
/**
1505+
* Search agents by identifier keys
1506+
*/
1507+
identifier_keys?: Array<string> | null;
1508+
1509+
/**
1510+
* Search agents by identity ID
1511+
*/
1512+
identity_id?: string | null;
1513+
1514+
/**
1515+
* Filter agents by their last stop reason.
1516+
*/
1517+
last_stop_reason?: RunsAPI.StopReasonType | null;
1518+
1519+
/**
1520+
* If True, only counts agents that match ALL given tags. Otherwise, counts agents
1521+
* that have ANY of the passed-in tags.
1522+
*/
1523+
match_all_tags?: boolean;
1524+
1525+
/**
1526+
* Name of the agent
1527+
*/
1528+
name?: string | null;
1529+
1530+
/**
1531+
* Search agents by project ID - this will default to your default project on cloud
1532+
*/
1533+
project_id?: string | null;
1534+
1535+
/**
1536+
* Search agents by name
1537+
*/
1538+
query_text?: string | null;
1539+
1540+
/**
1541+
* List of tags to filter agents by
1542+
*/
1543+
tags?: Array<string> | null;
1544+
1545+
/**
1546+
* Search agents by template ID
1547+
*/
1548+
template_id?: string | null;
1549+
}
1550+
14941551
export interface AgentExportFileParams {
14951552
/**
14961553
* @deprecated
@@ -1811,6 +1868,7 @@ export declare namespace Agents {
18111868
type AgentCreateParams as AgentCreateParams,
18121869
type AgentRetrieveParams as AgentRetrieveParams,
18131870
type AgentListParams as AgentListParams,
1871+
type AgentCountParams as AgentCountParams,
18141872
type AgentExportFileParams as AgentExportFileParams,
18151873
type AgentImportFileParams as AgentImportFileParams,
18161874
type AgentModifyParams as AgentModifyParams,

src/resources/agents/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export {
2626
type AgentCreateParams,
2727
type AgentRetrieveParams,
2828
type AgentListParams,
29+
type AgentCountParams,
2930
type AgentExportFileParams,
3031
type AgentImportFileParams,
3132
type AgentModifyParams,

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export {
2626
type AgentCreateParams,
2727
type AgentRetrieveParams,
2828
type AgentListParams,
29+
type AgentCountParams,
2930
type AgentExportFileParams,
3031
type AgentImportFileParams,
3132
type AgentModifyParams,

tests/api-resources/agents/agents.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ describe('resource agents', () => {
111111
expect(dataAndResponse.response).toBe(rawResponse);
112112
});
113113

114+
// Prism tests are disabled
115+
test.skip('count: request options and params are passed correctly', async () => {
116+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
117+
await expect(
118+
client.agents.count(
119+
{
120+
base_template_id: 'base_template_id',
121+
identifier_keys: ['string'],
122+
identity_id: 'identity_id',
123+
last_stop_reason: 'end_turn',
124+
match_all_tags: true,
125+
name: 'name',
126+
project_id: 'project_id',
127+
query_text: 'query_text',
128+
tags: ['string'],
129+
template_id: 'template_id',
130+
},
131+
{ path: '/_stainless_unknown_path' },
132+
),
133+
).rejects.toThrow(Letta.NotFoundError);
134+
});
135+
114136
// Prism tests are disabled
115137
test.skip('exportFile', async () => {
116138
const responsePromise = client.agents.exportFile('agent_id');

0 commit comments

Comments
 (0)