Agent Foundry
All Problems

#82. Structured Inter-Agent Messages

MediumMulti-Agent

The Problem

You have a two-agent pipeline for processing customer feedback: an extractor pulls out key fields (customer name, issue, product) and an analyzer classifies sentiment and priority. Currently the extractor passes its output as free-text prose, and the analyzer sometimes misinterprets or loses important fields. Your task is to switch to structured messages (e.g., Pydantic models or typed dictionaries) so that all fields are explicitly named and reliably preserved across agent boundaries.

Examples

Example 1

User input: "I'm John and my ProMax laptop screen flickered twice today. Very frustrated!"

Current (bad) output: The extractor outputs a paragraph like "The customer John reported a screen flickering issue with a ProMax laptop." The analyzer receives this text, sometimes misses the product name, and outputs an incomplete analysis.

Expected (good) output: The extractor outputs a structured object: {"customer_name": "John", "issue": "screen flickered twice", "product": "ProMax laptop"}. The analyzer parses these fields and returns {"sentiment": "negative", "priority": "high", "customer_name": "John", "product": "ProMax laptop"}.

Example 2

User input: "Sarah here — love the new CloudSync feature on my TabletX. Works great!"

Current (bad) output: The extractor buries the product name in prose. The analyzer may output a sentiment but without clear product attribution.

Expected (good) output: Structured extraction: {"customer_name": "Sarah", "issue": "positive feedback on CloudSync feature", "product": "TabletX"}. Structured analysis: {"sentiment": "positive", "priority": "low"}.

Your Task

Refactor the starter code so that:

  • A structured schema (Pydantic model or typed dict) defines the message format between agents.
  • The extractor outputs structured data conforming to the schema.
  • The analyzer receives and parses the structured data, preserving all fields.
  • No key information is lost between agents.

Evaluation

Submissions are checked for the following:

  • Structured schema defined: A Pydantic model or equivalent schema defines the inter-agent message format.
  • All fields preserved: Key information (customer name, issue, product) is not lost between agents.
  • Receiver parses structured data: The receiving agent parses the structured message rather than treating it as raw text.

Constraints

  • Agents must communicate using structured data models, not free-text strings
  • Define explicit schemas (e.g., Pydantic models) for inter-agent messages
  • The receiving agent must parse the structured message, not treat it as raw text
  • All key information fields must be preserved across agent boundaries
Starter Code
from crewai import Agent, Task, Crew, Process
from crewai import LLM

llm = LLM(model="gpt-4o-mini")

extractor = Agent(
    role="Data Extractor",
    goal="Extract key information from customer feedback",
    backstory="You parse customer reviews for actionable insights.",
    llm=llm,
)

analyzer = Agent(
    role="Sentiment Analyzer",
    goal="Analyze sentiment and priority from extracted data",
    backstory="You classify feedback by sentiment and urgency.",
    llm=llm,
)

# BUG: Extractor passes raw text — analyzer loses key fields
# TODO: Use structured output so all fields are preserved
extract_task = Task(
    description="Extract the customer name, issue, and product from this feedback: '{feedback}'",
    expected_output="The extracted customer name, issue description, and product name",
    agent=extractor,
)

analyze_task = Task(
    description="Analyze the sentiment and assign a priority level",
    expected_output="Sentiment (positive/negative/neutral) and priority (low/medium/high)",
    agent=analyzer,
)

crew = Crew(
    agents=[extractor, analyzer],
    tasks=[extract_task, analyze_task],
    process=Process.sequential,
)

result = crew.kickoff(inputs={"feedback": "I'm John and my ProMax laptop screen flickered twice today. Very frustrated!"})
print(result)
Open in Google Colab
Evaluation Criteria0/3