0
0
Prompt Engineering / GenAIml~20 mins

LangChain agents in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LangChain Agent Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding LangChain Agent Types

Which LangChain agent type is best suited for tasks that require calling multiple tools in a sequence based on user input?

AAgent that dynamically selects and chains multiple tools based on input.
BConversational agent designed for chat-based interactions without tool usage.
CAgent with memory that stores past interactions but does not use tools.
DZero-shot agent that uses a single tool without prior examples.
Attempts:
2 left
💡 Hint

Think about which agent can decide which tools to use and in what order.

Predict Output
intermediate
2:00remaining
Output of LangChain Agent Tool Call

What will be the output of this LangChain agent code snippet when the input is 'Translate hello to French'?

Prompt Engineering / GenAI
from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI

def translate(text):
    translations = {'hello': 'bonjour'}
    return translations.get(text.lower(), 'unknown')

tools = [Tool(name='translator', func=translate, description='Translate English to French')]
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent='zero-shot-react-description', verbose=False)

output = agent.run('Translate hello to French')
print(output)
Abonjour
BTranslate hello to French
CError: Tool function not found
Dunknown
Attempts:
2 left
💡 Hint

Check how the translate function maps 'hello' to French.

Hyperparameter
advanced
2:00remaining
Choosing Temperature for LangChain Agent LLM

You want your LangChain agent to give very precise and consistent answers without creativity. Which temperature setting for the underlying LLM is best?

ATemperature = -1.0 to disable randomness.
BTemperature = 0.0 for deterministic output.
CTemperature = 0.7 for balanced creativity and accuracy.
DTemperature = 1.0 for maximum creativity.
Attempts:
2 left
💡 Hint

Lower temperature means less randomness.

Metrics
advanced
2:00remaining
Evaluating LangChain Agent Performance

Which metric is most appropriate to evaluate a LangChain agent's ability to correctly use tools and provide accurate answers?

APerplexity of the underlying language model.
BBLEU score measuring text similarity to reference answers.
CMean Squared Error between predicted and true values.
DAccuracy of tool usage and final answer correctness.
Attempts:
2 left
💡 Hint

Think about what matters for an agent using tools to answer questions.

🔧 Debug
expert
3:00remaining
Debugging LangChain Agent Tool Integration

Given this LangChain agent code, what is the cause of the error when running the agent?

Prompt Engineering / GenAI
from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI

def calculator(input):
    return eval(input)

tools = [Tool(name='calc', func=calculator, description='Performs calculations')]
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent='zero-shot-react-description', verbose=False)

result = agent.run('Calculate 2 + 2')
print(result)
AThe tool name 'calc' is not recognized by the agent causing a lookup error.
BThe agent cannot parse 'Calculate 2 + 2' because it expects 'calc 2 + 2'.
CThe OpenAI LLM is not initialized with an API key, causing authentication failure.
DThe 'calculator' function uses eval which is unsafe and blocked by LangChain.
Attempts:
2 left
💡 Hint

Check if the LLM initialization is complete and authorized.