Aleksey Matsarski
Refactoring code, provide better abstraction and file structure
a47e415
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from agents.earnings_agent.tools import fetch_earnings_tool
from pathlib import Path
import yaml
yaml_path = Path(__file__).parent / "prompts.yaml"
with yaml_path.open() as f:
prompt_template = yaml.safe_load(f)
def create_earnings_agent(model) -> AgentExecutor:
prompt = ChatPromptTemplate.from_messages(
[
("system", prompt_template["system"]),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
]
)
agent = create_tool_calling_agent(llm=model, tools=[fetch_earnings_tool], prompt=prompt)
return AgentExecutor(agent=agent, tools=[fetch_earnings_tool], verbose=False, handle_parsing_errors=True)