Skip to content

Commit

Permalink
fix: supervisor not producing desired output (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou authored Dec 14, 2024
1 parent 3a252c1 commit 86a0a95
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 107 deletions.
27 changes: 10 additions & 17 deletions example/src/ecommerce_product_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import path from 'path'

const techExpert = agent({
description: `
You are skilled at extracting and describing most detailed
technical information about the product from the photo.
You are skilled at extracting and describing most detailed technical information about the product from the photo.
`,
tools: {
visionTool,
Expand All @@ -18,29 +17,23 @@ const techExpert = agent({

const marketingManager = agent({
description: `
You are skilled at writing catchy product descriptions
making customers to instantly fall in love with the product.
Use the technical information provided by the technical expert to create a compelling product description.
You are skilled at writing catchy product descriptions making customers to instantly fall in love with the product.
You always answer why they should buy the product, how it will make their life better,
and what emotions it will evoke.
`,
})

const productDescriptionWorkflow = workflow({
team: { techExpert, marketingManager },
description: `
Based on the picture '${path.resolve(import.meta.dirname, '../assets/example-sneakers.jpg')}' make the eCommerce product to
list this product on the website.
Focus:
- find all technical features of the product
- color, size, material, brand if possible, etc.
- write a compelling product description
- why they should buy this product?
- how it will make their life better?
- emotions?
Based on the picture '${path.resolve(import.meta.dirname, '../assets/example-sneakers.jpg')}'
make the product description to list it on the website.
`,
knowledge: `
Focus on all technical features of the product, including color, size, material, brand if possible, etc.
`,
output: `
Catchy, yet detailed product description that will make customers to instantly fall in love with the product.
Should contain all the product features + marketing description.
Catchy product description covering all the product features.
`,
snapshot: logger,
})
Expand Down
12 changes: 5 additions & 7 deletions example/src/github_trending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ const wrapupRedactor = agent({
const wrapUpTrending = workflow({
team: { githubResearcher, wrapupRedactor },
description: `
Research the URL "https://github.com/trending/typescript" page using firecrawl tool
Summarize information about 3 top projects into a comprehensive report markdown output.
Here are some ground rules to follow:
- Include one sentence summary for each project.
Research the "https://github.com/trending/typescript" page.
Summarize information about 3 top projects into a comprehensive markdown report.
Include one sentence summary for each project.
`,
knowledge: `
We are preparing a report for the Typescript community.
We are preparing a report for the TypeScript community.
`,
output: `
Comprehensive markdown report with the top trending typescript projects.
Comprehensive markdown report with the top trending TypeScript projects.
`,
snapshot: logger,
})
Expand Down
35 changes: 14 additions & 21 deletions example/src/github_trending_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { firecrawl } = createFireCrawlTool({
const webCrawler = agent({
description: `
You are skilled at browsing Web pages.
You are saving the documents to vector store for later usage.
You can save the documents to Vector store for later usage.
`,
tools: {
firecrawl,
Expand All @@ -39,9 +39,8 @@ const human = agent({

const reportCompiler = agent({
description: `
You can search Vector Store to find relevant informations and create reports based on it
Based on the information from Vector Store you can compile a comprehensive report.
You're famous of beautiful Markdown formatting.
You can create a comprehensive report based on the information from Vector store.
You're famous for beautiful Markdown formatting.
`,
tools: {
searchInVectorStore,
Expand All @@ -51,26 +50,20 @@ const reportCompiler = agent({
const wrapUpTrending = workflow({
team: { webCrawler, human, reportCompiler },
description: `
Research the URL "https://github.com/trending/typescript" page.
Select 3 top projects. Browse details about these projects on their subpages.
Store each page in Vector Store for further usage.
After you store the information you don't need to browse the page again
because everything is stored in Vector Store.
Ask user about which project he wants to learn more. Ask user only once.
`,
Research the "https://github.com/trending/typescript" page.
Select 3 top projects.
For each project, browse details about it on their subpages.
Store each page in Vector store for later usage.
Ask user about which project he wants to learn more.
`,
knowledge: `
Create a comprehensive markdown report using information from Vector Store, based on user selection:
- create a one, two sentence summary about every project.
- include detailed summary about the project selected by the user.
Here are some ground rules to follow:
- Use Vector Store if you need information about the project.
Each document in Vector store is a page from the website.
`,
output: `
Comprehensive markdown report including:
- summary on top trending Typescript projects.
- detailed info about the project selected by the user.
Create a comprehensive markdown report:
- create a one, two sentences summary about every project.
- include detailed summary about the project selected by the user.
`,
snapshot: logger,
})
Expand Down
18 changes: 12 additions & 6 deletions example/src/library_photo_to_website.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from 'node:fs/promises'
import path from 'node:path'

import { createFileSystemTools } from '@fabrice-ai/tools/filesystem'
import { visionTool } from '@fabrice-ai/tools/vision'
import { agent } from 'fabrice-ai/agent'
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 path from 'path'

const workingDir = path.resolve(import.meta.dirname, '../assets/')

Expand All @@ -16,7 +18,7 @@ const { saveFile, readFile, listFilesFromDirectory } = createFileSystemTools({
const librarian = agent({
description: `
You are skilled at scanning and identifying books in the library.
When asked, you will analyze the photo of the library and list all the books that you see, in details.
You can analyze the photo of the library and list all the books that you see, in details.
`,
tools: {
visionTool,
Expand All @@ -39,21 +41,25 @@ const webmaster = agent({
const imagePath = path.join(workingDir, 'photo-library.jpg')
const outputPath = path.join(workingDir, 'library.html')

await fs.rm(outputPath, { force: true })

const bookLibraryWorkflow = workflow({
team: { librarian, webmaster },
description: `
Analyze the photo of the library and list all the books in the library.
Generate a website that lists all the books in the library.
Find the best template to use for the website.
Copy the template to "${outputPath}" file.
Replace the content of the new with the list of books.
`,
knowledge: `
Important information:
- The photo of books in the library is in the "${imagePath}" file.
- All available templates are in "${workingDir}" directory. Find the best template to use.
- All available templates are in "${workingDir}" directory.
- You only have access to files in "${workingDir}" directory.
- Use absolute paths for tool calls.
`,
`,
output: `
Create a new HTML page in "${outputPath}" directory, based on the best template you found.
Valid HTML page with the list of books in the library, stored in "${outputPath}" file.
`,
snapshot: logger,
})
Expand Down
37 changes: 13 additions & 24 deletions example/src/medical_survey/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { askUser } from '../tools/askUser.js'
const nurse = agent({
description: `
You are skilled nurse / doctor assistant.
You role is to cooperate with reporter to create a pre-visit note for a patient that is about to come for a visit.
Ask user questions about the patient's health and symptoms.
Ask one question at time up to 5 questions.
Analyze the answer and ask another question based on the answer and context.
You are proffesional and kind.
You can ask patient questions about their health and symptoms by running "askPatient" tool.
You can only ask one question at a time.
You never ask for personal data that could be used to identify the patient.
`,
tools: {
askPatient: askUser,
Expand All @@ -27,29 +29,16 @@ const reporter = agent({
export const preVisitNoteWorkflow = workflow({
team: { nurse, reporter },
description: `
Create a pre-visit note for a patient that is about to come for a visit.
The note should include the patient's health and symptoms.
`,
knowledge: `
Behaviour:
- be professional and kind,
- ask questions one at a time,
- listen and analyze the answer before asking another question,
- be inquisitive and ask for details.
Interview a patient that is about to come for a visit.
Include:
You can only ask up to 5 questions in total.
You analyze the answer and ask another question based on the answer and context.
`,
output: `
Comprehensive markdown pre-visit report that covers:
- symptoms,
- health issues,
- medications,
- allergies,
- surgeries
Never ask fo:
- personal data,
- sensitive data,
- any data that can be used to identify the patient.
`,
output: `
A markdown report for the patient's pre-visit note.
- any other relevant information.
`,
})
12 changes: 4 additions & 8 deletions example/src/news_wrap_up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ const wrapupRedactor = agent({
description: `
Your role is to wrap up the news and trends for the last week into a comprehensive report.
Generalization is also one of your powerfull skills, however you're not a fortune teller.
You're famous of precisely getting the overal picture, trends and summarizing it all.
You're famous for precisely getting the overal picture, trends and summarizing it all.
`,
})

const wrapUpTheNewsWorkflow = workflow({
team: { newsResearcher, newsReader, wrapupRedactor },
description: `
Research the top news and trends for the last week - get title and headline description.
Then summarize it all into a comprehensive report markdown output.
`,
knowledge: `
Here are some ground rules to follow:
- Include one sentence summary for each article.
- Include top takeaways - bulletpoints from each article.
Research the top news and trends for the last week.
`,
output: `
Comprehensive markdown report with the listing including top news headlines for the last week.
- Include one sentence summary for each article.
- Include top takeaways - bulletpoints from each article.
`,
snapshot: logger,
})
Expand Down
16 changes: 8 additions & 8 deletions example/src/surprise_trip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const personalizedActivityPlanner = agent({
description: `
You are skilled at creating personalized itineraries that cater to
the specific preferences and demographics of travelers.
Your goal is to research and find cool things to do at the destination,
Your research and find cool things to do at the destination,
including activities and events that match the traveler's interests and age group.
`,
})

const landmarkScout = agent({
description: `
You are skilled at researching and finding interesting landmarks at the destination.
Your goal is to find historical landmarks, museums, and other interesting places.
Your find historical landmarks, museums, and other interesting places.
`,
tools: {
lookupWikipedia,
Expand All @@ -28,16 +28,14 @@ const restaurantScout = agent({
description: `
As a food lover, you know the best spots in town for a delightful culinary experience.
You also have a knack for finding picturesque and entertaining locations.
Your goal is to find highly-rated restaurants and dining experiences at the destination,
Your find highly-rated restaurants and dining experiences at the destination,
and recommend scenic locations and fun activities.
`,
})

const itineraryCompiler = agent({
description: `
With an eye for detail, you organize all the information into a coherent and enjoyable travel plan.
Your goal is to compile all researched information into a comprehensive day-by-day itinerary,
ensuring the integration of flights and hotel information.
`,
})

Expand Down Expand Up @@ -65,10 +63,12 @@ const researchTripWorkflow = workflow({
- Hotel location: Main Square, Wrocław
- Flight information: Flight AA123, arriving on 2023-12-15
- How long is the trip: 7 days
`,
Consider flights confirmed.
`,
output: `
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.
Comprehensive day-by-day plan for the trip to Wrocław, Poland.
Ensure the plan includes flights, hotel information, and all planned activities and dining experiences.
`,
})

Expand Down
24 changes: 10 additions & 14 deletions example/src/wikipedia_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const { saveDocumentInVectorStore, searchInVectorStore } = createVectorStoreTool
const wikipediaIndexer = agent({
description: `
You are skilled at reading and understanding the context of Wikipedia articles.
You split Wikipedia articles by each sentence.
Save each sentence as a document in Vector store.
You can save Wikipedia articles in Vector store for later use.
When saving articles in Vector store, you only save first 10 sentences.
`,
tools: {
lookupWikipedia,
Expand All @@ -24,8 +24,7 @@ const wikipediaIndexer = agent({
const reportCompiler = agent({
description: `
You are skilled at compiling information from various sources into a coherent report.
You have access to Vector database with indexed sentences of Wikipedia articles.
You are making use of it to find relevant information.
You can search for specific sentences in Vector database.
`,
tools: {
searchInVectorStore,
Expand All @@ -35,19 +34,16 @@ const reportCompiler = agent({
const wikipediaResearch = workflow({
team: { wikipediaIndexer, reportCompiler },
description: `
Find information about John III Sobieski on Wikipedia.
Index the data into vector database.
List exact some example sentences related to:
- Battle of Vienna.
- John III later years and death.
Find information about John III Sobieski on Wikipedia and save it in Vector store.
Lookup sentences related to the following topics:
- "Battle of Vienna"
- "John III later years and death"
`,
knowledge:`
Wikipedia article should be splited into sentences.
Every sentence should be stored as a document in Vector Store.
knowledge: `
Each document in Vector store is a sentence.
`,
output: `
Report with:
- bullet points - list of 2 sentences per each topic from vector store.
List of sentences looked up for each topic. Each sentence should be in separate bullet point.
`,
snapshot: logger,
})
Expand Down
7 changes: 5 additions & 2 deletions packages/framework/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ export const rootState = (workflow: Workflow): WorkflowState =>
messages: [
user(s`
Here is description of my workflow:
<workflow>${workflow.description}</workflow>
<output>${workflow.output}</output>
<workflow>
${workflow.description}
Create ${workflow.output}
</workflow>
Here is all the knowledge available:
<knowledge>${workflow.knowledge}</knowledge>
`),
Expand Down

0 comments on commit 86a0a95

Please sign in to comment.