Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: supervisor not producing desired output #121

Merged
merged 9 commits into from
Dec 14, 2024
Merged

fix: supervisor not producing desired output #121

merged 9 commits into from
Dec 14, 2024

Conversation

grabbou
Copy link
Collaborator

@grabbou grabbou commented Dec 14, 2024

This PR started as a quick work to clean-up examples, but it quickly revealed a bug in supervisor that I decided to fix, and test.

Motivation

First of all, let me start with cosmetic changes to examples and motivations behind them. I wanted to make sure the examples use the following rules:

Workflow:

  • Description: Use it to describe the task to be done. Do not include information about what is the output. Just the tasks on how to achieve it.
  • Knowledge: Use it to describe universal information about the tasks, useful for both supervisor and agents, such as "why are we doing this" or "information about patient".
  • Output: Use it to describe what must be produced.

Agent:

  • Description: Describe agent's behavior and capabilities. Do not describe "tasks".

I have provided inline comments alongside examples to point out real examples.

Bug

Then, I quickly discovered the bug, that supervisor is often returning null and not producing desired output, despite finishing all the steps.

I console.logged reasoning and here's what I found:

{
  task: null,
  reasoning: "Both questions allowed by the workflow have been asked: one about symptoms and another about medications and allergies. The responses provided cover the necessary information for the pre-visit report. The patient reported a sore throat as a symptom, is taking ibuprofen, and has an allergy to ibuprofen. With this information, I can now generate the comprehensive markdown pre-visit report as requested in the output.",
}

or

{
  task: null,
  reasoning: "All tasks in the workflow have been completed. Information about John III Sobieski was successfully found and stored in the vector store. Sentences related to both 'Battle of Vienna' and 'John III later years and death' have been looked up and retrieved from the vector store. Therefore, the output, which is a list of sentences for each topic, can now be generated.",
}

As you can see, supervisor was thinking the workflow was completed when all the steps were finished, returning null. This is somewhat true, but also, the last and final task should always be to produce the desired output.

I slightly changed the workflow request to include generating output as a last step.


Examples

Medical Surevy Output

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ nurse Working on: Ask the first question to the patient: 'What symptoms are you currently experiencing?'

supervisor 
  └─▶ nurse Waiting for tools: askPatient

❔What symptoms are you currently experiencing?
sore throat
supervisor 
  └─▶ nurse Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ nurse Working on: Ask the second question to the patient: 'Are you currently taking any medications for your sore throat or any other condition?'

supervisor 
  └─▶ nurse Waiting for tools: askPatient

❔Are you currently taking any medications for your sore throat or any other condition?
ibuprofen
supervisor 
  └─▶ nurse Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ nurse Working on: Ask the third question to the patient: 'Do you have any known allergies, especially to medications?'

supervisor 
  └─▶ nurse Waiting for tools: askPatient

❔Do you have any known allergies, especially to medications?
not aware
supervisor 
  └─▶ nurse Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ nurse Working on: Ask the fourth question to the patient: 'Have you experienced any other symptoms or health issues recently that you think might be relevant?'

supervisor 
  └─▶ nurse Waiting for tools: askPatient

❔Have you experienced any other symptoms or health issues recently that you think might be relevant?
small fatigue
supervisor 
  └─▶ nurse Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ nurse Working on: Ask the fifth question to the patient: 'Have you visited any healthcare provider recently or had any medical tests done?'

supervisor 
  └─▶ nurse Waiting for tools: askPatient

❔Have you visited any healthcare provider recently or had any medical tests done?
no
supervisor 
  └─▶ nurse Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ reporter Working on: Create a comprehensive markdown pre-visit report that covers the patient's symptoms, medications, allergies, and any other relevant information.

supervisor Looking for next task...

supervisor Looking for next task...

# Patient Pre-Visit Report

## Patient Symptoms
- **Primary Symptom:** Sore throat
- **Additional Symptoms:** Small fatigue

## Current Medications
- **Medication:** Ibuprofen (taken for sore throat or another condition)

## Allergies
- **Known Allergies:** The patient has no known allergies, including to medications.

## Recent Medical History
- **Healthcare Provider Visits:** The patient has not visited any healthcare provider recently.
- **Medical Tests:** No recent medical tests have been undertaken.

---

This report summarizes the current health status as discussed by the patient. It is intended to provide a clear overview ahead of the patient's visit, ensuring comprehensive care.

Surprise Trip

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ personalizedActivityPlanner Working on: Research activities and events in Wrocław, Poland that match the traveler's interests and age group (30 years old).

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ restaurantScout Working on: Research highly-rated restaurants and dining experiences in Wrocław, Poland.

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ landmarkScout Working on: Research landmarks with historic context in Wrocław, Poland.

supervisor 
  └─▶ landmarkScout Waiting for tools: lookupWikipedia

supervisor 
  └─▶ landmarkScout Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ restaurantScout Working on: Research picturesque and entertaining locations in Wrocław, Poland.

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ itineraryCompiler Working on: Compile the researched activities, restaurants, landmarks, and picturesque locations into a day-by-day itinerary for the 7-day trip.

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ itineraryCompiler Working on: Generate Comprehensive day-by-day plan for the trip to Wrocław, Poland.

supervisor Looking for next task...

supervisor Looking for next task...

I've gathered all the necessary information and tasks previously researched and will now create a comprehensive and detailed plan for the 7-day trip to Wrocław, Poland, ensuring it aligns with the traveler's interests and the available information.

**Day 1: Arrival and Leisure Introduction**
- **15:00:** Arrive in Wrocław on Flight AA123.
- **16:30:** Check in at your hotel located at Main Square.
- **19:00:** Casual evening stroll around the Main Market Square (Rynek) to absorb the local architecture and atmosphere.
- **20:00:** Dinner at Bernard for an introduction to Czech and Polish cuisine.

**Day 2: Historical and Cultural Immersion**
- **09:00:** Start your day with exploring Wrocław Cathedral and Ostrów Tumski, the historical core of the city.
- **12:00:** Enjoy a traditional Polish lunch at Pod Fredrą, near the Main Square.
- **14:00:** Visit the Panorama of the Battle of Racławice for a historic art experience.
- **17:00:** A quick walk through Wrocław's Historical Museum located in the City Hall.
- **19:30:** Dinner at Kurna Chata for a deep dive into rustic Polish culinary delights.

**Day 3: Artistic Exploration and Evening Entertainment**
- **09:30:** Visit the Contemporary Museum Wrocław, dive into modern art exhibits.
- **12:30:** Lunch at Vincent, savoring French cuisine.
- **15:00:** Explore The University of Wrocław and appreciate its Baroque architecture.
- **19:00:** Attend an evening performance at Wrocław Opera or the Philharmonic Hall.
- **21:00:** Late dinner at Restaurant Jadka, known for its modern Polish dishes.

**Day 4: Scenic Retreat and Relaxation**
- **09:00:** Spend your morning at the Botanical Garden of the University of Wrocław.
- **12:00:** Lunch at Przystań & Marina offering scenic views of the Odra River.
- **15:00:** A leisure walk across Tumski Bridge with lovely river views.
- **18:00:** Dinner at Vincent with fine French dining.

**Day 5: Animals and Outdoor Leisure**
- **10:00:** Visit the Wrocław Zoo and Afrykarium to experience its distinctive water complex.
- **13:00:** Have a casual lunch at any cozy eatery around the Market Square.
- **16:00:** Spend the afternoon relaxing at Słodowa Island, ideal for a picnic.
- **19:00:** Enjoy the vibrant nightlife, exploring the local pubs and bars around the Main Square.

**Day 6: Festive Delight and Architectural Appreciation**
- **09:00:** Experience the Wrocław Christmas Market for festive shopping and treats.
- **13:00:** Have lunch in the Market Square from diverse options available.
- **15:00:** Tour the Centennial Hall (Hala Stulecia) and appreciate this UNESCO Heritage Site’s modern architecture.
- **19:00:** Dinner at Bernard with an eclectic menu, followed by a night of exploring the local pubs.

**Day 7: Last Experiential Day and Departure**
- **09:00:** A final walk around the Market Square capturing photos and checking out last-minute shops or cafes.
- **12:00:** Light lunch at a nearby café to your accommodation.
- **14:00:** If time permits, visit the National Museum for insightful exhibits.
- **17:00:** Departure preparations.
- **Evening:** Depart for your return flight to New York.

This detailed itinerary caters to diverse interests including history, art, outdoor leisure, and cultural festivities, providing a well-rounded travel experience in Wrocław.

Wikipedia

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ wikipediaIndexer Working on: Find information about John III Sobieski on Wikipedia.

supervisor 
  └─▶ wikipediaIndexer Waiting for tools: lookupWikipedia

supervisor 
  └─▶ wikipediaIndexer Processing tool response...

supervisor 
  └─▶ wikipediaIndexer Waiting for tools: saveDocumentInVectorStore

supervisor 
  └─▶ wikipediaIndexer Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ reportCompiler Working on: Lookup sentences related to the topic "Battle of Vienna" in the vector store.

supervisor 
  └─▶ reportCompiler Waiting for tools: searchInVectorStore

supervisor 
  └─▶ reportCompiler Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ reportCompiler Working on: Lookup sentences related to the topic "John III later years and death" in the vector store.

supervisor 
  └─▶ reportCompiler Waiting for tools: searchInVectorStore

supervisor 
  └─▶ reportCompiler Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ reportCompiler Working on: Create a list of sentences looked up for each topic, with each sentence in a separate bullet point.

supervisor Looking for next task...

supervisor Looking for next task...

For the topic "Battle of Vienna":
- Popular among his subjects, he was an able military leader, most famously for his victory over the Ottoman Empire at the Battle of Vienna in 1683. The defeated Ottomans named Sobieski the 'Lion of Lechistan', and the Pope hailed him as the saviour of Western Christendom.

For the topic "John III later years and death":
- Suffering from poor health and obesity in later life, Sobieski died in 1696 and was buried at Wawel Cathedral in Kraków. He was succeeded by Augustus II of Poland and Saxony.

Ecommerce

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ techExpert Working on: Analyze the image '/Users/grabbou/Repositories/dead-simple-ai-agent/example/assets/example-sneakers.jpg' to identify and note down all visible technical features such as color, size, material, and brand.

supervisor 
  └─▶ techExpert Working on: functions.visionTool

supervisor 
  └─▶ techExpert Waiting for tools: visionTool

supervisor 
  └─▶ techExpert Processing tool response...

supervisor Looking for next task...

supervisor 
  └─▶ resourcePlanner Looking for best agent...

supervisor 
  └─▶ marketingManager Working on: Create a catchy product description using the identified features: navy blue high-top sneakers with a canvas upper, white rubber toe cap, white laces, white stitching, and a two-tone sole with a black stripe.

supervisor Looking for next task...

supervisor Looking for next task...

Step into timeless elegance with our captivating Navy Blue High-Top Sneakers. Crafted from a durable canvas upper, these sneakers are a perfect blend of style and comfort. The sophisticated navy blue hue, enhanced by exquisite white stitching, makes them an instant classic in your shoe collection. 

Featuring a chic high-top design, complemented by a distinctive white rubber toe cap and matching white laces, these sneakers exude a sporty yet refined look. The two-tone sole with a sleek black stripe not only adds a dynamic touch but also promises ultimate grip and support with every step you take.

These sneakers are not just footwear; they are a statement. A statement that says you value both form and function, adventure and leisure. Whether you're out exploring the city streets or enjoying a casual weekend brunch, these sneakers will elevate every outfit and occasion.

Why choose these sneakers? Because they're more than just a pair of shoes—they are a versatile companion for your life's journeys, ready to take you wherever your heart desires, all while evoking a sense of confidence and style.

Template

```md supervisor └─▶ resourcePlanner Looking for best agent...

supervisor
└─▶ librarian Working on: Analyze the photo of the library and list all the books in the library.

supervisor
└─▶ librarian Working on: functions.visionTool

supervisor
└─▶ librarian Waiting for tools: visionTool

supervisor
└─▶ librarian Processing tool response...

supervisor Looking for next task...

supervisor
└─▶ resourcePlanner Looking for best agent...

supervisor
└─▶ webmaster Working on: Find the best template to use for the website from the available templates in the "/Users/grabbou/Repositories/dead-simple-ai-agent/example/assets" directory.

supervisor
└─▶ webmaster Waiting for tools: listFilesFromDirectory

supervisor
└─▶ webmaster Processing tool response...

supervisor Looking for next task...

supervisor
└─▶ resourcePlanner Looking for best agent...

supervisor
└─▶ webmaster Working on: Copy the template 'book_library_template.html' to '/Users/grabbou/Repositories/dead-simple-ai-agent/example/assets/library.html'.

supervisor
└─▶ webmaster Waiting for tools: readFile

supervisor
└─▶ webmaster Processing tool response...

supervisor
└─▶ webmaster Waiting for tools: saveFile

supervisor
└─▶ webmaster Processing tool response...

supervisor Looking for next task...

supervisor
└─▶ resourcePlanner Looking for best agent...

supervisor
└─▶ webmaster Working on: Replace the content of '/Users/grabbou/Repositories/dead-simple-ai-agent/example/assets/library.html' with the list of books.

supervisor
└─▶ webmaster Waiting for tools: readFile

supervisor
└─▶ webmaster Processing tool response...

supervisor
└─▶ webmaster Working on: Replace placeholder content with actual book list

supervisor
└─▶ webmaster Waiting for tools: saveFile

supervisor
└─▶ webmaster Processing tool response...

supervisor Looking for next task...

supervisor Looking for next task...

The list of books has been successfully incorporated into the HTML template and saved to '/Users/grabbou/Repositories/dead-simple-ai-agent/example/assets/library.html'.

</details>

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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent doesn't know who provides the input, so I rephrased it a bit.
I also moved "requirements" from workflow description to agent, as this is "how" that applies to that one specifically


Here are some ground rules to follow:
- Include one sentence summary for each project.
Research the "https://github.com/trending/typescript" page.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed "using fire crawl tool", as the how is handled by responsible agent.

@@ -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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to expressing capabilities instead of orders

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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined lines 42 and 43 into one, as they were very close to each other

`,
knowledge: `
Behaviour:
- be professional and kind,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to agent description, as it describes nurse capabilities more than universal knowledge to all agents

- medications,
- allergies,
- surgeries
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed number of things to focus on. Previously, due to how this workflow was structured, it would ask up to 5 questions FOR EACH area, making it hard to complete this without having to answer ~10-15 questions.

Decreasing number of areas of focus and increasing number of questions allows the system to both ask comprehensive set of questions, and also do follow-ups.

@@ -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,
Copy link
Collaborator Author

@grabbou grabbou Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed goal as this should go to workflow description.

@@ -65,7 +64,9 @@ 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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make comprehensive report, it wants to confirm flights, which it doesn't have APIs. So to avoid erroring from time to time, we make this explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, replaced word literary with plan.

@grabbou
Copy link
Collaborator Author

grabbou commented Dec 14, 2024

Also @pkarw I have issues with Github Trending example - content of website too large exceeded context window
Wikipedia Vector - I don't think it saves sentences - the tool is not called n times, but just once.

@pkarw
Copy link
Collaborator

pkarw commented Dec 14, 2024

Great job @grabbou, thanks for this effort 🙏 I've checked the changes and suggested only one minor change

@grabbou grabbou marked this pull request as ready for review December 14, 2024 06:18
@pkarw pkarw merged commit 86a0a95 into main Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants