Skip to content

Commit

Permalink
feat: add knowledge to agent (#108)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grabbou authored Dec 13, 2024
1 parent 7067632 commit 3626c15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example/src/surprise_trip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const researchTripWorkflow = workflow({
- highly-rated restaurants and dining experiences.
- landmarks with historic context.
- picturesque and entertaining locations.
`,
knowledge: `
Traveler's information:
- Origin: New York, USA
- Destination: Wrocław, Poland
Expand All @@ -70,7 +71,6 @@ const researchTripWorkflow = workflow({
Comprehensive day-by-day itinerary for the trip to Wrocław, Poland.
Ensure the itinerary integrates flights, hotel information, and all planned activities and dining experiences.
`,
snapshot: logger,
})

const result = await teamwork(researchTripWorkflow)
Expand Down
16 changes: 14 additions & 2 deletions packages/framework/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const agent = (options: AgentOptions = {}): Agent => {
provider,
run:
options.run ??
(async (state, context) => {
(async (state, context, workflow) => {
const mappedTools = tools
? Object.entries(tools).map(([name, tool]) =>
zodFunction({
Expand All @@ -39,6 +39,8 @@ export const agent = (options: AgentOptions = {}): Agent => {
)
: []

const [, ...messages] = context

const response = await provider.completions({
messages: [
{
Expand All @@ -62,7 +64,17 @@ export const agent = (options: AgentOptions = {}): Agent => {
},
{
role: 'user',
content: `Here is all the work done so far by other agents: ${JSON.stringify(context)}`,
content: `Here is all the work done so far by other agents: ${JSON.stringify(messages)}`,
},
{
role: 'assistant',
content: 'Is there anything else I need to know?',
},
{
role: 'user',
content: workflow.knowledge
? `Here is all the knowledge available: ${workflow.knowledge}`
: 'No, I do not have any additional information.',
},
{
role: 'assistant',
Expand Down
5 changes: 4 additions & 1 deletion packages/framework/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type WorkflowOptions = {

team: Team

knowledge?: string
provider?: Provider
maxIterations?: number
snapshot?: Telemetry
Expand All @@ -37,4 +38,6 @@ export const workflow = (options: WorkflowOptions): Workflow => {
}
}

export type Workflow = Required<WorkflowOptions>
export type Workflow = Required<Omit<WorkflowOptions, 'knowledge'>> & {
knowledge?: string
}

0 comments on commit 3626c15

Please sign in to comment.