Skip to content

Commit ff8e209

Browse files
committed
Merge branch 'main' of https://github.com/wrtnlabs/agentica
2 parents f70b527 + 1f01cc0 commit ff8e209

File tree

9 files changed

+179
-1373
lines changed

9 files changed

+179
-1373
lines changed

packages/core/prompts/execute.md

Lines changed: 69 additions & 338 deletions
Large diffs are not rendered by default.

packages/core/prompts/json_parse_error.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ ${{ERROR_MESSAGE}}
1818
- Function execution cannot proceed
1919

2020
### Required Action:
21-
- **Retry the function call** with **valid JSON format**
22-
- Fix the JSON syntax error indicated above
23-
- Ensure proper JSON structure in the `arguments` field
21+
- Review the error message above and determine whether the JSON is recoverable
22+
- If the syntax error is minor (e.g. trailing comma, missing quote), fix it and retry
23+
- If the JSON is severely malformed or structurally broken, **discard the previous output entirely** and reconstruct the `arguments` from scratch based on the function's parameter schema
24+
- Do not attempt to patch heavily corrupted JSON — rebuilding from zero is faster and more reliable
2425

2526
### Common JSON Syntax Requirements:
2627
- Use double quotes for all keys and string values
@@ -29,4 +30,4 @@ ${{ERROR_MESSAGE}}
2930
- Use lowercase `null` for null values
3031
- Properly escape special characters in strings
3132

32-
**Please correct the JSON format and retry the function call immediately.**
33+
**Retry the function call immediately with valid JSON.**

packages/core/prompts/validate.md

Lines changed: 70 additions & 996 deletions
Large diffs are not rendered by default.

packages/core/src/orchestrate/call.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ export async function call(
5050
const completion = await retryFn(async (prevError) => {
5151
const result = await ctx.request("call", {
5252
messages: [
53-
// COMMON SYSTEM PROMPT
54-
{
55-
role: "system",
56-
content: AgenticaDefaultPrompt.write(ctx.config),
57-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
5853
// PREVIOUS HISTORIES
5954
...ctx.histories.map(decodeHistory).flat(),
6055
// USER INPUT
@@ -78,6 +73,11 @@ export async function call(
7873
content: ctx.config?.systemPrompt?.execute?.(ctx.histories as MicroAgenticaHistory[])
7974
?? AgenticaSystemPrompt.EXECUTE,
8075
} satisfies OpenAI.ChatCompletionSystemMessageParam]),
76+
// COMMON SYSTEM PROMPT
77+
{
78+
role: "system",
79+
content: AgenticaDefaultPrompt.write(ctx.config),
80+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
8181
],
8282
// STACKED FUNCTIONS
8383
tools: operations.map(
@@ -357,11 +357,6 @@ async function correctError(
357357

358358
const result = await ctx.request("call", {
359359
messages: [
360-
// COMMON SYSTEM PROMPT
361-
{
362-
role: "system",
363-
content: AgenticaDefaultPrompt.write(ctx.config),
364-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
365360
// PREVIOUS HISTORIES
366361
...ctx.histories.map(decodeHistory).flat(),
367362
// USER INPUT
@@ -398,6 +393,11 @@ async function correctError(
398393
role: "system",
399394
content: props.systemPrompt,
400395
},
396+
// COMMON SYSTEM PROMPT
397+
{
398+
role: "system",
399+
content: AgenticaDefaultPrompt.write(ctx.config),
400+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
401401
],
402402
// STACK FUNCTIONS
403403
tools: [

packages/core/src/orchestrate/cancel.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ async function step(
9797
// ----
9898
const result = await ctx.request("cancel", {
9999
messages: [
100-
// COMMON SYSTEM PROMPT
101-
{
102-
role: "system",
103-
content: AgenticaDefaultPrompt.write(ctx.config),
104-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
105100
// CANDIDATE FUNCTIONS
106101
{
107102
role: "assistant",
@@ -149,6 +144,10 @@ async function step(
149144
},
150145
// TYPE CORRECTIONS
151146
...emendMessages(failures ?? []),
147+
{
148+
role: "system",
149+
content: AgenticaDefaultPrompt.write(ctx.config),
150+
},
152151
],
153152
// STACK FUNCTIONS
154153
tools: [{

packages/core/src/orchestrate/describe.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export async function describe(
2222

2323
const result = await ctx.request("describe", {
2424
messages: [
25-
// COMMON SYSTEM PROMPT
26-
{
27-
role: "system",
28-
content: AgenticaDefaultPrompt.write(ctx.config),
29-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
3025
// FUNCTION CALLING HISTORIES
3126
...histories.map(decodeHistory).flat(),
3227
// SYSTEM PROMPT
@@ -36,6 +31,11 @@ export async function describe(
3631
ctx.config?.systemPrompt?.describe?.(histories)
3732
?? AgenticaSystemPrompt.DESCRIBE,
3833
},
34+
// COMMON SYSTEM PROMPT
35+
{
36+
role: "system",
37+
content: AgenticaDefaultPrompt.write(ctx.config),
38+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
3939
],
4040
});
4141

packages/core/src/orchestrate/initialize.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ export async function initialize(ctx: AgenticaContext): Promise<void> {
2424
// ----
2525
const result = await ctx.request("initialize", {
2626
messages: [
27-
// COMMON SYSTEM PROMPT
28-
{
29-
role: "system",
30-
content: AgenticaDefaultPrompt.write(ctx.config),
31-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
3227
// PREVIOUS HISTORIES
3328
...ctx.histories.map(decodeHistory).flat(),
3429
// USER INPUT
3530
{
3631
role: "user",
3732
content: ctx.prompt.contents.map(decodeUserMessageContent),
3833
},
34+
// SYSTEM PROMPT
3935
{
40-
// SYSTEM PROMPT
4136
role: "system",
4237
content:
4338
ctx.config?.systemPrompt?.initialize?.(ctx.histories)
4439
?? AgenticaSystemPrompt.INITIALIZE,
4540
},
41+
// COMMON SYSTEM PROMPT
42+
{
43+
role: "system",
44+
content: AgenticaDefaultPrompt.write(ctx.config),
45+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
4646
],
4747
// GETTER FUNCTION
4848
tools: [

packages/core/src/orchestrate/select.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ async function step(
110110
const completion = await retryFn(async (prevError) => {
111111
const result = await ctx.request("select", {
112112
messages: [
113-
// COMMON SYSTEM PROMPT
114-
{
115-
role: "system",
116-
content: AgenticaDefaultPrompt.write(ctx.config),
117-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
113+
118114
// CANDIDATE FUNCTIONS
119115
{
120116
role: "assistant",
@@ -171,6 +167,11 @@ async function step(
171167
},
172168
// TYPE CORRECTIONS
173169
...emendMessages(failures ?? []),
170+
// COMMON SYSTEM PROMPT
171+
{
172+
role: "system",
173+
content: AgenticaDefaultPrompt.write(ctx.config),
174+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
174175
],
175176
// STACK FUNCTIONS
176177
tools: [{

packages/vector-selector/src/select.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export async function selectFunction(props: {
2222
const { ctx, toolList, prevFailures = [], restRetry = 5 } = props;
2323
const selectCompletion = await ctx.request("select", {
2424
messages: [
25-
{
26-
role: "system",
27-
content: AgenticaDefaultPrompt.write(ctx.config),
28-
},
2925
{
3026
role: "assistant",
3127
tool_calls: [
@@ -60,6 +56,10 @@ export async function selectFunction(props: {
6056
`,
6157
},
6258
...emendMessages(prevFailures),
59+
{
60+
role: "system",
61+
content: AgenticaDefaultPrompt.write(ctx.config),
62+
},
6363
],
6464
tool_choice: {
6565
type: "function",

0 commit comments

Comments
 (0)