Spaces:
Sleeping
Sleeping
Delete agent.py
Browse files
agent.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
| 1 |
-
from typing import TypedDict, Annotated
|
| 2 |
-
from langgraph.graph.message import add_messages
|
| 3 |
-
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage
|
| 4 |
-
from langgraph.prebuilt import ToolNode
|
| 5 |
-
from langgraph.graph import START, StateGraph
|
| 6 |
-
from langgraph.prebuilt import tools_condition
|
| 7 |
-
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 8 |
-
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 9 |
-
from tools import *
|
| 10 |
-
|
| 11 |
-
# Generate the chat interface, including the tools
|
| 12 |
-
llm = HuggingFaceEndpoint(
|
| 13 |
-
repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 14 |
-
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 18 |
-
|
| 19 |
-
tools = [
|
| 20 |
-
search_tool
|
| 21 |
-
]
|
| 22 |
-
|
| 23 |
-
chat_with_tools = chat.bind_tools(tools)
|
| 24 |
-
|
| 25 |
-
# Generate the AgentState and Agent graph
|
| 26 |
-
class AgentState(TypedDict):
|
| 27 |
-
messages: Annotated[list[AnyMessage], add_messages]
|
| 28 |
-
|
| 29 |
-
def assistant(state: AgentState):
|
| 30 |
-
return {
|
| 31 |
-
"messages": [chat_with_tools.invoke(state["messages"])],
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
## The graph
|
| 35 |
-
builder = StateGraph(AgentState)
|
| 36 |
-
|
| 37 |
-
# Define nodes: these do the work
|
| 38 |
-
builder.add_node("assistant", assistant)
|
| 39 |
-
builder.add_node("tools", ToolNode(tools))
|
| 40 |
-
|
| 41 |
-
# Define edges: these determine how the control flow moves
|
| 42 |
-
builder.add_edge(START, "assistant")
|
| 43 |
-
builder.add_conditional_edges(
|
| 44 |
-
"assistant",
|
| 45 |
-
# If the latest message requires a tool, route to tools
|
| 46 |
-
# Otherwise, provide a direct response
|
| 47 |
-
tools_condition,
|
| 48 |
-
)
|
| 49 |
-
builder.add_edge("tools", "assistant")
|
| 50 |
-
agent = builder.compile()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|