Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Nov 14, 2024
1 parent 4d198be commit 1f4f27b
Show file tree
Hide file tree
Showing 5 changed files with 2,065 additions and 479 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ jobs:
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
LANGSMITH_TRACING: true
LANGSMITH_TEST_CACHE: tests/cassettes
run: |
uv run pytest tests/integration_tests
23 changes: 9 additions & 14 deletions src/react_agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Dict, List, Literal, cast

from langchain_core.messages import AIMessage
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableConfig
from langgraph.graph import StateGraph
from langgraph.prebuilt import ToolNode
Expand Down Expand Up @@ -36,25 +35,21 @@ async def call_model(
"""
configuration = Configuration.from_runnable_config(config)

# Create a prompt template. Customize this to change the agent's behavior.
prompt = ChatPromptTemplate.from_messages(
[("system", configuration.system_prompt), ("placeholder", "{messages}")]
)

# Initialize the model with tool binding. Change the model or add more tools here.
model = load_chat_model(configuration.model).bind_tools(TOOLS)

# Prepare the input for the model, including the current system time
message_value = await prompt.ainvoke(
{
"messages": state.messages,
"system_time": datetime.now(tz=timezone.utc).isoformat(),
},
config,
# Format the system prompt. Customize this to change the agent's behavior.
system_message = configuration.system_prompt.format(
system_time=datetime.now(tz=timezone.utc).isoformat()
)

# Get the model's response
response = cast(AIMessage, await model.ainvoke(message_value, config))
response = cast(
AIMessage,
await model.ainvoke(
[{"role": "system", "content": system_message}, *state.messages], config
),
)

# Handle the case when it's the last step and the model still wants to use a tool
if state.is_last_step and response.tool_calls:
Expand Down
Loading

0 comments on commit 1f4f27b

Please sign in to comment.