Skip to content

Commit ab5f609

Browse files
committed
feat: add knowledge to agent (#108)
We separate knowledge from workflow description to avoid tasks/descriptions interfering with agent. This could possibly be something else in the future, like a method that gets it from the database/something. This is just demonstration, as alternative to #105. I am still not sure about this.
1 parent aab1c36 commit ab5f609

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

example/src/surprise_trip.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const researchTripWorkflow = workflow({
5757
- highly-rated restaurants and dining experiences.
5858
- landmarks with historic context.
5959
- picturesque and entertaining locations.
60-
60+
`,
61+
knowledge: `
6162
Traveler's information:
6263
- Origin: New York, USA
6364
- Destination: Wrocław, Poland
@@ -70,7 +71,6 @@ const researchTripWorkflow = workflow({
7071
Comprehensive day-by-day itinerary for the trip to Wrocław, Poland.
7172
Ensure the itinerary integrates flights, hotel information, and all planned activities and dining experiences.
7273
`,
73-
snapshot: logger,
7474
})
7575

7676
const result = await teamwork(researchTripWorkflow)

packages/framework/src/agent.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const agent = (options: AgentOptions = {}): Agent => {
2828
provider,
2929
run:
3030
options.run ??
31-
(async (state, context) => {
31+
(async (state, context, workflow) => {
3232
const mappedTools = tools
3333
? Object.entries(tools).map(([name, tool]) =>
3434
zodFunction({
@@ -39,6 +39,8 @@ export const agent = (options: AgentOptions = {}): Agent => {
3939
)
4040
: []
4141

42+
const [, ...messages] = context
43+
4244
const response = await provider.completions({
4345
messages: [
4446
{
@@ -62,7 +64,17 @@ export const agent = (options: AgentOptions = {}): Agent => {
6264
},
6365
{
6466
role: 'user',
65-
content: `Here is all the work done so far by other agents: ${JSON.stringify(context)}`,
67+
content: `Here is all the work done so far by other agents: ${JSON.stringify(messages)}`,
68+
},
69+
{
70+
role: 'assistant',
71+
content: 'Is there anything else I need to know?',
72+
},
73+
{
74+
role: 'user',
75+
content: workflow.knowledge
76+
? `Here is all the knowledge available: ${workflow.knowledge}`
77+
: 'No, I do not have any additional information.',
6678
},
6779
{
6880
role: 'assistant',

packages/framework/src/workflow.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type WorkflowOptions = {
1111

1212
team: Team
1313

14+
knowledge?: string
1415
provider?: Provider
1516
maxIterations?: number
1617
snapshot?: Telemetry
@@ -37,4 +38,6 @@ export const workflow = (options: WorkflowOptions): Workflow => {
3738
}
3839
}
3940

40-
export type Workflow = Required<WorkflowOptions>
41+
export type Workflow = Required<Omit<WorkflowOptions, 'knowledge'>> & {
42+
knowledge?: string
43+
}

0 commit comments

Comments
 (0)