0
0
LangChainframework~20 mins

Multi-agent graphs in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-agent Graph Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this multi-agent graph execution?
Consider a Langchain multi-agent graph where Agent A sends a message to Agent B, which then replies back to Agent A with a transformed message. What will Agent A receive after the graph runs?
LangChain
from langchain.agents import Agent

class AgentA(Agent):
    def __init__(self, name):
        super().__init__(name)
    def respond(self, message):
        return f"Received: {message}"

class AgentB(Agent):
    def __init__(self, name):
        super().__init__(name)
    def respond(self, message):
        return message.upper()

# Setup graph
agent_a = AgentA(name="A")
agent_b = AgentB(name="B")

message = "hello"
response_b = agent_b.respond(message)
response_a = agent_a.respond(response_b)

print(response_a)
A"Received: HELLO"
B"hello"
C"HELLO"
D"Received: hello"
Attempts:
2 left
💡 Hint
Think about how Agent B transforms the message before Agent A receives it.
state_output
intermediate
2:00remaining
What is the final state of the multi-agent graph after message passing?
In a Langchain multi-agent graph, Agent X stores every message it receives in a list called 'history'. After sending three messages "one", "two", "three" to Agent X, what is the content of Agent X's history?
LangChain
from langchain.agents import Agent

class AgentX(Agent):
    def __init__(self, name):
        super().__init__(name)
        self.history = []
    def respond(self, message):
        self.history.append(message)
        return f"Ack: {message}"

agent_x = AgentX(name="X")
messages = ["one", "two", "three"]
for msg in messages:
    agent_x.respond(msg)

print(agent_x.history)
A["Ack: one", "Ack: two", "Ack: three"]
B["one", "two", "three"]
C[]
D["one", "two"]
Attempts:
2 left
💡 Hint
Check what is appended to the history list inside respond().
🔧 Debug
advanced
2:00remaining
Why does this multi-agent graph code raise an AttributeError?
This Langchain multi-agent graph code raises an AttributeError when trying to access 'last_message' attribute. Identify the cause.
LangChain
from langchain.agents import Agent

class AgentY(Agent):
    def __init__(self, name):
        super().__init__(name)
    def respond(self, message):
        self.last_message = message
        return f"Got: {message}"

agent_y = AgentY(name="Y")
print(agent_y.last_message)
AThe variable 'agent_y' is not instantiated correctly.
BThe respond method is missing a return statement.
CThe attribute 'last_message' is not set before print is called.
DAgentY class does not inherit from Agent properly.
Attempts:
2 left
💡 Hint
When is 'last_message' assigned in the code?
📝 Syntax
advanced
2:00remaining
Which option correctly defines a multi-agent graph with cyclic message passing?
You want to create two agents, Agent1 and Agent2, that send messages to each other in a cycle. Which code snippet correctly implements this behavior without syntax errors?
A
class Agent1(Agent):
    def respond(self, message):
        return Agent2().respond(message + " from Agent1")

class Agent2(Agent):
    def respond(self, message):
        return Agent1().respond(message + " from Agent2")
B
class Agent1(Agent):
    def respond(self, message):
        return self.agent2.respond(message + " from Agent1")

class Agent2(Agent):
    def respond(self, message):
        return self.agent1.respond(message + " from Agent2")

agent1 = Agent1()
agent2 = Agent2()
agent1.agent2 = agent2
C
class Agent1(Agent):
    def respond(self, message):
        return self.agent2.respond(message + " from Agent1")

class Agent2(Agent):
    def respond(self, message):
        return self.agent1.respond(message + " from Agent2")
D
class Agent1(Agent):
    def __init__(self):
        super().__init__("Agent1")
        self.agent2 = None
    def respond(self, message):
        return self.agent2.respond(message + " from Agent1")

class Agent2(Agent):
    def __init__(self):
        super().__init__("Agent2")
        self.agent1 = None
    def respond(self, message):
        return self.agent1.respond(message + " from Agent2")

agent1 = Agent1()
agent2 = Agent2()
agent1.agent2 = agent2
agent2.agent1 = agent1
Attempts:
2 left
💡 Hint
Check if both agents have references to each other before calling respond.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using a multi-agent graph in Langchain?
Select the best explanation for why multi-agent graphs are used in Langchain applications.
AThey allow multiple agents to collaborate and share information dynamically, enabling complex workflows and decision-making.
BThey simplify single-agent tasks by reducing code complexity and removing the need for message passing.
CThey replace the need for external APIs by embedding all knowledge inside one agent.
DThey guarantee faster execution by running all agents in parallel without any communication overhead.
Attempts:
2 left
💡 Hint
Think about how multiple agents working together can improve problem solving.