| name | langchain-2-agent-with-tools |
| description | Sub-skill of langchain: 2. Agent with Tools. |
| version | 1.0.0 |
| category | ai-prompting |
| type | reference |
| scripts_exempt | true |
2. Agent with Tools
2. Agent with Tools
ReAct Agent with Custom Tools:
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_core.tools import tool
from langchain import hub
from typing import Optional
import requests
json
() -> :
math
suspended_length = math.sqrt(line_length** - depth**)
stretch_factor = + (offset / suspended_length) *
tension = pretension * stretch_factor
json.dumps({
: (tension, ),
: (tension * (depth / line_length), ),
: (math.degrees(math.asin(depth / line_length)), )
})
() -> :
wave_data = {
: location,
: ,
: ,
: ,
:
}
json.dumps(wave_data)
() -> :
results = {
: query,
: [
{: , : },
{: , : },
{: , : }
]
}
json.dumps(results)
():
llm = ChatOpenAI(model=, temperature=)
tools = [
calculate_mooring_tension,
get_wave_data,
search_engineering_database
]
prompt = hub.pull()
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=,
handle_parsing_errors=,
max_iterations=
)
agent_executor
agent = create_engineering_agent()
response = agent.invoke({
:
})
(response[])