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 committed Dec 13, 2024
1 parent 73a6495 commit cdfe46e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 2 additions & 3 deletions example/src/surprise_trip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { agent } from 'fabrice-ai/agent'
import { parallelSupervisor } from 'fabrice-ai/agents/supervisor'
import { solution } from 'fabrice-ai/solution'
import { teamwork } from 'fabrice-ai/teamwork'
import { logger } from 'fabrice-ai/telemetry'
import { workflow } from 'fabrice-ai/workflow'

import { lookupWikipedia } from './tools/wikipedia.js'
Expand Down Expand Up @@ -59,7 +58,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 @@ -72,7 +72,6 @@ const researchTripWorkflow = workflow({
Comprehensive day-by-day itinerary for the trip to Wrocław, Poland.
Ensure the itinerary includes flights, hotel information, and all planned activities and dining experiences.
`,
snapshot: logger,
})

const result = await teamwork(researchTripWorkflow)
Expand Down
12 changes: 10 additions & 2 deletions packages/framework/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -41,6 +41,8 @@ export const agent = (options: AgentOptions = {}): Agent => {
)
: []

const [, ...messages] = context

const res = await provider.completions({
messages: [
{
Expand All @@ -59,7 +61,13 @@ export const agent = (options: AgentOptions = {}): Agent => {
`,
},
response('What have been done so far?'),
request(`Here is all the work done so far by other agents: ${JSON.stringify(context)}`),
request(
`Here is all the work done so far by other agents: ${JSON.stringify(messages)}`
),
response(`Is there anything else I need to know?`),
workflow.knowledge
? request(`Here is all the knowledge available: ${workflow.knowledge}`)
: request(`No, I do not have any additional information.`),
response('What do you want me to do now?'),
...state.messages,
],
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/agents/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ParallelSupervisorOptions = AgentOptions & {
parallelism?: number
}

export const parallelSupervisor = (options: ParallelSupervisorOptions) => {
export const parallelSupervisor = (options: ParallelSupervisorOptions = {}) => {
const { parallelism = 3 } = options

return agent({
Expand Down Expand Up @@ -78,7 +78,7 @@ export const parallelSupervisor = (options: ParallelSupervisorOptions) => {
})
}

export const supervisor = (options: AgentOptions) => {
export const supervisor = (options?: AgentOptions) => {
return agent({
run: async (state, context, workflow) => {
const [workflowRequest, ...messages] = state.messages
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 cdfe46e

Please sign in to comment.