-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfinal_boss.ts
43 lines (40 loc) · 1.15 KB
/
final_boss.ts
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
import s from 'dedent'
import { zodResponseFormat } from 'openai/helpers/zod'
import { z } from 'zod'
import { agent, AgentOptions } from '../agent.js'
import { finish, request, response } from '../state.js'
const defaults: AgentOptions = {
run: async (state, context, workflow) => {
const res = await workflow.team[state.agent].provider.completions({
messages: [
{
role: 'system',
content: s`
You exceeded max steps.
`,
},
...context,
request(s`
Please summarize all executed steps and do your best to achieve
the main goal while responding with the final answer
`),
],
response_format: zodResponseFormat(
z.object({
finalAnswer: z.string().describe('The final result of the task'),
}),
'task_result'
),
})
const message = res.choices[0].message.parsed
if (!message) {
throw new Error('No parsed response received')
}
return finish(state, response(message.finalAnswer))
},
}
export const finalBoss = (options?: AgentOptions) =>
agent({
...defaults,
...options,
})