Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created October 22, 2025 10:19
Show Gist options
  • Save larkintuckerllc/8bb33c599e89f96879cda3ce95c3c80d to your computer and use it in GitHub Desktop.
Save larkintuckerllc/8bb33c599e89f96879cda3ce95c3c80d to your computer and use it in GitHub Desktop.
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_agent
from langchain.tools import tool
@tool
def get_weather(city: str) -> str:
"""Get weather for a given city.
Args:
city: The city to get the weather for
"""
return f"It's always sunny in {city}!"
def main():
llm = ChatAnthropic(
model="claude-sonnet-4-5",
max_tokens=1000
)
agent = create_agent(
model=llm,
tools=[get_weather],
system_prompt="You are a helpful assistant",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "what is the weather in sf"}]}
)
final_message = result["messages"][-1]
print(final_message.content)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment