0
0
LangChainframework~10 mins

Custom agent logic in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the base class for creating a custom agent in LangChain.

LangChain
from langchain.agents import [1]
Drag options to blanks, or click blank then click option'
ABaseSingleActionAgent
BAgentOutputParser
CAgentExecutor
DAgentToolkit
Attempts:
3 left
💡 Hint
Common Mistakes
Importing AgentExecutor instead of the base agent class
Confusing output parser with agent base class
2fill in blank
medium

Complete the method signature to define the custom agent's decision logic.

LangChain
def plan(self, intermediate_steps, [1]):
Drag options to blanks, or click blank then click option'
Aoutputs
Binputs
Cactions
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'outputs' instead of 'inputs'
Using unrelated parameter names
3fill in blank
hard

Fix the error in the code to correctly return the agent's action.

LangChain
return [1](tool='search', tool_input=inputs['query'])
Drag options to blanks, or click blank then click option'
AAgentResponse
BAgentOutput
CAgentStep
DAgentAction
Attempts:
3 left
💡 Hint
Common Mistakes
Using AgentOutput which is for final output
Using non-existent classes like AgentStep
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps tool names to their descriptions.

LangChain
tool_descriptions = {tool.[1]: tool.[2] for tool in tools}
Drag options to blanks, or click blank then click option'
Aname
Bdescription
Ctool_name
Ddesc
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like 'tool_name' or 'desc'
Swapping keys and values
5fill in blank
hard

Fill all three blanks to define a custom agent class with a name, a method, and a return statement.

LangChain
class CustomAgent([1]):
    def [2](self, intermediate_steps, inputs):
        return f"Hello, [3]!"
Drag options to blanks, or click blank then click option'
ABaseSingleActionAgent
Bgreet
Cinputs['name']
Dplan
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name other than 'plan'
Not inheriting from the correct base class
Incorrectly accessing input data