Using anthropic sdk via langchain_anthropic integration
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage, SystemMessage
from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool
@tool
def type_letter(letter: str) -> str:
"""Type the given letter."""
return "OK"
model = ChatAnthropic(model="claude-3-haiku-20240307", temperature=0).bind_tools([type_letter])
messages = [
SystemMessage(content="Repeat the given string using the provided tools. Do not write anything else or provide any explanations. For example, if the string is 'abc', you must print the letters 'a', 'b', and 'c' one at a time and in that order. "),
HumanMessage(content="dog")
]
model.invoke(messages)
The SDK can return empty text blocks from models:
ToolsBetaMessage(id='msg_01D6BbZbwbPYRVMPVu5SZRTp', content=[TextBlock(text='', type='text'), ToolUseBlock(id='toolu_01YHFB1pLY3xNa1edzoV4HtL', input={'letter': 'd'}, name='type_letter', type='tool_use'), ToolUseBlock(id='toolu_011ewRdDypyE8yHMniYT2gzj', input={'letter': 'o'}, name='type_letter', type='tool_use'), ToolUseBlock(id='toolu_01YKV1QaDPePiAFQVwmrSmjk', input={'letter': 'g'}, name='type_letter', type='tool_use')], model='claude-3-haiku-20240307', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=Usage(input_tokens=395, output_tokens=125))
However, the SDK does not accept empty text block if re-interacting with the model (e.g., if using an agent).
Using anthropic sdk via langchain_anthropic integration
The SDK can return empty text blocks from models:
However, the SDK does not accept empty text block if re-interacting with the model (e.g., if using an agent).