Bird
Raised Fist0
Agentic AIml~20 mins

Agent API design patterns in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Agent API Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the role of the 'Planner' in Agent API design

In an agent API design pattern, what is the primary role of the 'Planner' component?

AIt executes the actions decided by the agent without modification.
BIt decides the sequence of actions the agent should take to achieve its goal.
CIt stores the agent's memory and past interactions for future reference.
DIt handles the user interface and visual representation of the agent.
Attempts:
2 left
💡 Hint

Think about which part of the agent figures out what to do next.

Predict Output
intermediate
2:00remaining
Output of agent action execution with error handling

What will be the output of the following agent API code snippet when the action 'fetch_data' fails?

Agentic AI
class Agent:
    def __init__(self):
        self.actions = {'fetch_data': self.fetch_data}
    def fetch_data(self):
        raise Exception('Network error')
    def execute(self, action_name):
        try:
            return self.actions[action_name]()
        except Exception as e:
            return f'Error: {e}'
agent = Agent()
result = agent.execute('fetch_data')
print(result)
ANetwork error
BException: Network error
CNone
DError: Network error
Attempts:
2 left
💡 Hint

Look at the except block and what it returns.

Model Choice
advanced
2:00remaining
Choosing the best agent API pattern for dynamic task switching

Which agent API design pattern best supports dynamic switching between multiple tasks based on real-time input?

AHierarchical pattern with layered decision-making and task delegation.
BReactive pattern that immediately responds to inputs without internal state.
CBatch processing pattern that queues tasks and processes them sequentially.
DStatic pipeline pattern with fixed sequence of operations.
Attempts:
2 left
💡 Hint

Consider which pattern allows flexible control and task management.

Hyperparameter
advanced
2:00remaining
Impact of 'timeout' hyperparameter in agent API calls

In an agent API design, setting a 'timeout' hyperparameter controls:

AThe maximum time the agent waits for an action to complete before aborting.
BThe number of retries the agent makes after a failed action.
CThe priority level of the agent's tasks in the queue.
DThe size of the memory buffer storing past interactions.
Attempts:
2 left
💡 Hint

Think about what 'timeout' usually means in computing.

🔧 Debug
expert
3:00remaining
Debugging unexpected agent response in API design

An agent API is designed to return a JSON response with keys 'status' and 'result'. The following code snippet returns {'status': 'success'} but misses 'result'. What is the likely cause?

def agent_response(data):
    if data:
        return {'status': 'success'}
    else:
        return {'status': 'fail', 'result': None}
response = agent_response({'task': 'run'})
print(response)
AThe print statement is missing the 'result' key access.
BThe input data is empty, so the else branch is not executed.
CThe function does not include 'result' in the success case, causing incomplete response.
DThe function should return a string, not a dictionary.
Attempts:
2 left
💡 Hint

Check what keys are returned in each branch of the function.

Practice

(1/5)
1. What is the main purpose of using Agent API design patterns in AI systems?
easy
A. To organize how AI agents communicate and work together
B. To speed up the training of machine learning models
C. To store large datasets efficiently
D. To improve the hardware performance of AI servers

Solution

  1. Step 1: Understand the role of Agent API design patterns

    These patterns help define clear communication and interaction rules between AI agents.
  2. Step 2: Compare with other options

    Options A, C, and D relate to training speed, data storage, and hardware, which are not the focus of Agent API design patterns.
  3. Final Answer:

    To organize how AI agents communicate and work together -> Option A
  4. Quick Check:

    Agent API design patterns = organize communication [OK]
Hint: Agent API patterns focus on agent communication, not hardware or data [OK]
Common Mistakes:
  • Confusing design patterns with hardware optimization
  • Thinking patterns speed up model training directly
  • Mixing data storage with agent communication
2. Which of the following is the correct way to define a simple message passing function in an Agent API?
easy
A. def send_message(agent, message): return message + agent
B. def send_message(agent, message): agent.send(message)
C. def send_message(agent, message): return agent.receive(message)
D. def send_message(agent, message): print(agent + message)

Solution

  1. Step 1: Analyze the function purpose

    The function should send a message to an agent and get a response by calling the agent's receive method.
  2. Step 2: Check each option

    def send_message(agent, message): return agent.receive(message) correctly calls agent.receive(message). def send_message(agent, message): agent.send(message) calls agent.send which is not standard. Options A and C incorrectly try to add or print agent and message.
  3. Final Answer:

    def send_message(agent, message): return agent.receive(message) -> Option C
  4. Quick Check:

    Message passing calls agent.receive(message) [OK]
Hint: Message passing calls agent.receive(message) to send data [OK]
Common Mistakes:
  • Using agent.send instead of agent.receive
  • Trying to concatenate agent object with string
  • Printing instead of returning the message
3. Given the code below, what will be the output?
class Agent:
    def receive(self, message):
        return f"Received: {message}"

def send_message(agent, message):
    return agent.receive(message)

agent = Agent()
print(send_message(agent, "Hello"))
medium
A. Error: method not found
B. Hello
C. send_message(agent, Hello)
D. Received: Hello

Solution

  1. Step 1: Understand the Agent class and receive method

    The receive method returns the string 'Received: ' plus the message passed.
  2. Step 2: Trace the send_message call

    send_message calls agent.receive with "Hello", so it returns 'Received: Hello'.
  3. Final Answer:

    Received: Hello -> Option D
  4. Quick Check:

    agent.receive("Hello") = "Received: Hello" [OK]
Hint: Agent.receive returns 'Received: ' plus message [OK]
Common Mistakes:
  • Expecting just the message without prefix
  • Thinking send_message prints instead of returns
  • Assuming method does not exist causing error
4. Identify the error in the following Agent API code snippet:
class Agent:
    def receive(self, message):
        print(f"Got message: {message}")

def send_message(agent, message):
    return agent.receive(message)

agent = Agent()
response = send_message(agent, "Hi")
print(response)
medium
A. The receive method should return a value, not just print
B. send_message should not call agent.receive
C. Agent class is missing an __init__ method
D. The print statement in send_message is incorrect

Solution

  1. Step 1: Check receive method behavior

    receive only prints the message but does not return anything, so it returns None by default.
  2. Step 2: Analyze send_message and print(response)

    send_message returns None, so printing response outputs None, which is likely unintended.
  3. Final Answer:

    The receive method should return a value, not just print -> Option A
  4. Quick Check:

    receive must return message for send_message to work [OK]
Hint: receive must return, not just print, to pass data back [OK]
Common Mistakes:
  • Ignoring that print returns None
  • Thinking __init__ is required here
  • Confusing print location with syntax error
5. You want to design an Agent API where multiple agents can collaborate by passing messages and roles define their behavior. Which design pattern best supports this?
hard
A. Factory pattern to create agents dynamically
B. Mediator pattern to centralize communication between agents
C. Singleton pattern to ensure one agent instance
D. Observer pattern to notify agents of state changes

Solution

  1. Step 1: Understand collaboration and role-based behavior

    Agents need a central way to communicate and coordinate roles effectively.
  2. Step 2: Match design patterns to needs

    The Mediator pattern centralizes communication, making it ideal for agent collaboration. Singleton limits to one instance, Factory creates objects, Observer handles notifications but not central communication.
  3. Final Answer:

    Mediator pattern to centralize communication between agents -> Option B
  4. Quick Check:

    Collaboration with roles = Mediator pattern [OK]
Hint: Mediator centralizes agent communication for collaboration [OK]
Common Mistakes:
  • Choosing Singleton which limits to one agent
  • Confusing Factory with communication pattern
  • Using Observer which is for event notification only