Compare commits

...

2 Commits

Author SHA1 Message Date
Gilad Resisi
26c58fdad6 fix(agent): next postsListTool page keeps the same parameters
The paging hint said to repeat only the dates, which would drop a
"customer" filter on the following pages.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-21 17:19:24 +07:00
Gilad Resisi
dcad18742f fix(agent): page postsListTool results
postsListTool returned every post in the window with full content and
settings, and its description told the model to pass a wide window. On a
large organization a single tool result grew past the model provider's
10 MB per-output limit and the agent chat failed with
context_length_exceeded / "string too long".

Results are now sorted by publish date then id and returned 50 per page,
with an optional "page" input and additive "total", "page" and "hasMore"
outputs. The description and the agent prompt explain paging and prefer
narrow windows. getPosts is unchanged, the slice happens in the tool.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-21 14:36:47 +07:00
2 changed files with 32 additions and 9 deletions

View File

@ -85,7 +85,7 @@ export class LoadToolsService {
- In every message I will send you the list of needed social medias (id and platform), if you already have the information use it, if not, use the integrationSchema tool to get it.
- Make sure you always take the last information I give you about the socials, it might have changed.
- Before scheduling a post, always make sure you ask the user confirmation by providing all the details of the post (text, images, videos, date, time, social media platform, account).
- To find or inspect existing posts, use postsListTool with a UTC start and end date - it returns every post scheduled in that window. To cover "all my upcoming posts", pass a wide window starting now.
- To find or inspect existing posts, use postsListTool with a UTC start and end date - it returns the posts scheduled in that window, one page at a time ("total" and "hasMore" tell if there is more, pass the same parameters with "page" + 1 for the next page). Prefer a narrow window, and for many posts summarise instead of fetching every page.
- To change the provider settings of an existing post that was not published yet (scheduled or draft), first find it with postsListTool, then use postSettingsTool with the post's id. It only updates the settings - the content and the publish date stay as they are - and only the keys you pass are changed (get them with the integrationSchema tool). Show the user which post and which settings will change and get their confirmation first.
- Never open the "modal with populated content" to edit an existing post - that modal only CREATES a new post, so using it to edit would duplicate the post. It is only for brand new posts.
- You can create, schedule and update posts, but you CANNOT delete posts - there is no delete capability. Never offer to delete a post. If the user asks you to delete one, tell them deletion is a destructive action and they should delete it themselves in the Postiz app (the calendar).

View File

@ -9,6 +9,8 @@ import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);
const PAGE_SIZE = 50;
const parseSettings = (settings: string | null) => {
try {
return JSON.parse(settings || '{}');
@ -36,8 +38,9 @@ export class PostsListTool implements AgentToolInterface {
},
description: `
List the organization's posts scheduled to be published between two dates (the same data as the "List Posts" API endpoint).
Returns every post in the window whatever its state (scheduled, draft, published, errored).
"startDate" and "endDate" are required (UTC) - to list all upcoming posts, pass a wide window (for example from now to a year ahead).
Returns the posts in the window whatever their state (scheduled, draft, published, errored), ordered by publish date.
"startDate" and "endDate" are required (UTC) - prefer a narrow window (days or weeks) over a wide one.
Results are paged, ${PAGE_SIZE} posts per page: "total" is the number of posts in the window and "hasMore" tells if there are more pages - to get the next page, call again with the same parameters and "page" + 1 (the first page is 0).
Each item has an "id", its publish date, state, content, channel and current provider settings.
Posts cannot be deleted through the Postiz tools - if the user wants to delete a post, tell them to do it themselves in the Postiz app; never offer to delete a post.
`,
@ -52,6 +55,12 @@ Posts cannot be deleted through the Postiz tools - if the user wants to delete a
.string()
.optional()
.describe('Optional customer (group) id to filter the channels by'),
page: z
.number()
.int()
.min(0)
.optional()
.describe('Page number, starts at 0 (default 0)'),
}),
outputSchema: z.object({
output: z.object({
@ -72,6 +81,9 @@ Posts cannot be deleted through the Postiz tools - if the user wants to delete a
integrationName: z.string(),
})
),
total: z.number().describe('Number of posts in the window'),
page: z.number(),
hasMore: z.boolean().describe('True if there are more pages'),
}),
}),
execute: async (inputData, context) => {
@ -80,15 +92,23 @@ Posts cannot be deleted through the Postiz tools - if the user wants to delete a
(context?.requestContext as any)?.get('organization') as string
).id;
const posts = await this._postsService.getPosts(organizationId, {
startDate: inputData.startDate,
endDate: inputData.endDate,
customer: inputData.customer,
} as any);
const page = inputData.page || 0;
const all = (
(await this._postsService.getPosts(organizationId, {
startDate: inputData.startDate,
endDate: inputData.endDate,
customer: inputData.customer,
} as any)) || []
).sort(
(a: any, b: any) =>
dayjs(a.publishDate).valueOf() - dayjs(b.publishDate).valueOf() ||
a.id.localeCompare(b.id)
);
const posts = all.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE);
return {
output: {
posts: (posts || []).map((p: any) => ({
posts: posts.map((p: any) => ({
id: p.id,
publishDate: dayjs(p.publishDate)
.utc()
@ -101,6 +121,9 @@ Posts cannot be deleted through the Postiz tools - if the user wants to delete a
platform: p.integration?.providerIdentifier,
integrationName: p.integration?.name,
})),
total: all.length,
page,
hasMore: (page + 1) * PAGE_SIZE < all.length,
},
};
},