Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
]
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.11,<4.0"
requires-python = ">=3.12,<4.0"
dependencies = [
"langgraph>=0.2.6",
"langchain>=0.3.19",
Expand Down
14 changes: 8 additions & 6 deletions backend/src/agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


# Nodes
def generate_query(state: OverallState, config: RunnableConfig) -> QueryGenerationState:
def generate_query(state: OverallState, config: RunnableConfig) -> OverallState:
"""LangGraph node that generates search queries based on the User's question.

Uses Gemini 2.0 Flash to create an optimized search queries for web research based on
Expand Down Expand Up @@ -78,17 +78,17 @@ def generate_query(state: OverallState, config: RunnableConfig) -> QueryGenerati
)
# Generate the search queries
result = structured_llm.invoke(formatted_prompt)
return {"search_query": result.query}
return {"generated_query": result.query}


def continue_to_web_research(state: QueryGenerationState):
def continue_to_web_research(state: OverallState):
"""LangGraph node that sends the search queries to the web research node.

This is used to spawn n number of web research nodes, one for each search query.
"""
return [
Send("web_research", {"search_query": search_query, "id": int(idx)})
for idx, search_query in enumerate(state["search_query"])
for idx, search_query in enumerate(state["generated_query"])
]


Expand Down Expand Up @@ -253,9 +253,11 @@ def finalize_answer(state: OverallState, config: RunnableConfig):
# Replace the short urls with the original urls and add all used urls to the sources_gathered
unique_sources = []
for source in state["sources_gathered"]:
if source["short_url"] in result.content:
short_url = f"({source['short_url']})"
if short_url in result.content:
value = f"({source['value']})"
result.content = result.content.replace(
source["short_url"], source["value"]
short_url, value
)
unique_sources.append(source)

Expand Down
4 changes: 2 additions & 2 deletions backend/src/agent/state.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import TypedDict
from typing import TypedDict, Annotated

from langgraph.graph import add_messages
from typing_extensions import Annotated


import operator


class OverallState(TypedDict):
messages: Annotated[list, add_messages]
generated_query: list[str]
search_query: Annotated[list, operator.add]
web_research_result: Annotated[list, operator.add]
sources_gathered: Annotated[list, operator.add]
Expand Down