Passing formatted html to structured langchain tool #23926
Replies: 1 comment
-
@KMIntelligentSystems Hello there! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve this issue. To ensure that the agent passes the correct HTML string to the
from langchain_core.tools import BaseTool
class SaveDataInput(BaseTool):
name = "SaveDataInput"
description = "Tool to save HTML data input."
def __call__(self, html_data: str) -> None:
# Implement the logic to save the HTML data
pass
from langchain_core.language_models import BaseLanguageModel
from langchain_core.callbacks import BaseCallbackManager
from langchain.agents.structured_chat.base import StructuredChatAgent
from langchain.agents.structured_chat.output_parser import StructuredChatOutputParser
# Define the LLM and callback manager
llm = BaseLanguageModel() # Replace with actual LLM initialization
callback_manager = BaseCallbackManager() # Replace with actual callback manager initialization
# Define the tool
save_data_input_tool = SaveDataInput()
# Create the agent with the tool
agent = StructuredChatAgent.from_llm_and_tools(
llm=llm,
tools=[save_data_input_tool],
callback_manager=callback_manager
)
# Create the MRKL chain
mrkl_chain = MRKLChain(agent=agent, tools=[save_data_input_tool])
from langchain_core.agents import AgentAction, AgentFinish
from langchain.agents.structured_chat.output_parser import StructuredChatOutputParser
output_parser = StructuredChatOutputParser()
def parse_output(message: str):
output = output_parser.parse(message)
if isinstance(output, AgentAction):
return output.tool, str(output.tool_input)
elif isinstance(output, AgentFinish):
return output.return_values["output"], output.log
else:
raise ValueError("Unexpected output type") By following these steps, you ensure that the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
The Claude model produces the correct html as seen in the example code. The html is cast to str and passed as input to the structured tool which the model detects and runs. On entering the executing agent chain the output of the chain is in "System Info".
The agent output has "invoking:
SaveDataInput with
{}" which produces the error: "input field required (type=value_error.missing)" in the tool as you would expect with input
{}`. Why is the agent passing in {} when is a html string?System Info
"Invoking:
SaveDataInput
with{}
responded: [{'text': '\nThe SaveDataInput tool is relevant for this task, as it takes an HTML string as input and extracts the complete HTML from it.\n\nThe tool requires a single parameter:\n- input: The HTML input as a string\n\nThe user has provided the HTML code within the input string, so we have all the necessary information to call the SaveDataInput tool.\n\nNo other tools are needed, as the SaveDataInput tool alone can extract the complete HTML from the provided input string.\n', 'type': 'text'}, {'id': 'toolu_01Y3egcW8T6bcHc9RwqnSekv', 'input': {}, 'name': 'SaveDataInput', 'type': 'tool_use'}]"
Beta Was this translation helpful? Give feedback.
All reactions