Spaces:
Runtime error
Runtime error
Upload langgraph_agent.py
Browse files- langgraph_agent.py +45 -0
langgraph_agent.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_openai import ChatOpenAI
|
| 2 |
+
from langchain_core.messages import AnyMessage, HumanMessage
|
| 3 |
+
from langchain_core.runnables import RunnableConfig
|
| 4 |
+
from langgraph.prebuilt import create_react_agent
|
| 5 |
+
from langgraph.prebuilt.chat_agent_executor import AgentState
|
| 6 |
+
|
| 7 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
| 8 |
+
from langchain_experimental.utilities import PythonREPL
|
| 9 |
+
from langchain_community.tools import WikipediaQueryRun
|
| 10 |
+
from langchain_community.utilities import WikipediaAPIWrapper
|
| 11 |
+
|
| 12 |
+
BASE_URL = "https://api-prod.jll.com/csp/chat-service/api/v1"
|
| 13 |
+
OKTA_ACCESS_TOKEN = "eyJraWQiOiI2S1VzTVotcWNlQkkwc19QaG9QVUNpdG9kak9wdVE0TU9XNFAyY1RJUUM0IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULnk3bUZoZ0dVMjM4M3ZFMXRIemNXa1F5WkUwWlljUXNfUC1GOHlHOU9iYmMub2FyMXExaWY0OTFpeTIySnUwaDciLCJpc3MiOiJodHRwczovL2psbC5va3RhLmNvbS9vYXV0aDIvYXVzMWh3cmluaHFPUXBGOG4waDgiLCJhdWQiOiJhcGk6Ly9kZWZhdWx0IiwiaWF0IjoxNzQ3OTE4ODcwLCJleHAiOjE3NDc5MjI0NzAsImNpZCI6IjBvYTFza3lpcGV0MXRxUjJKMGg4IiwidWlkIjoiMDB1MXd2ZnQxY3pOUlZJZ2swaDgiLCJzY3AiOlsib3BlbmlkIiwicHJvZmlsZSIsIm9mZmxpbmVfYWNjZXNzIiwiZW1haWwiXSwiYXV0aF90aW1lIjoxNzQ3OTE4ODM5LCJzdWIiOiJEZXZhc3VyeWEuUkBqbGwuY29tIiwiQURHVUlEIjoiaVpWSFUwV2pyMDJaemJnYXBaRTEvUT09IiwiY29uc3VtZXJjbGFpbSI6Im9rdGFhdXRoc2VydmVyPWFwaW07amxsc3lzdGVtdXNlcj1hcGktY29uc3VtZXItY2hhdGdwdC1vaWRjO3BzaWQ9SkxMR1BUQFNFUlZJQ0U7In0.uzO3AZTTsxDJEBvEZa2KxOBf80kBEbmoWSzHJViTVBD0fpGOQz8ELlmAj0oGiR_ND9ZsMh5yZKRr3CNyD8nYsWF-nIY6IkeOtymUhbX41F7-Vjgpm4cxCJvVta78TGccRPLQptrCuiAXb4EqfN-_Bgsgx-wbDfOvgIwHBYV2i056u8dBnHOWzQAunGaFVeztVg-4hBjxXSUyFJoVC7ISvvvyWC7Y4DYN7xkoE8mznsxRCsAPOsZySdiFupGGZksW65pXNkSOA47Co1GnuB14yyYU8-OYcd6lu58AKDDMUl2vyJ0bSShhBjiCmrIS6I4_7ru4ldCusWcujJjR-Jm5vQ"
|
| 14 |
+
SUBSCRIPTION_KEY = "e3c3d48a04e04f10be62efffd0f972ac"
|
| 15 |
+
|
| 16 |
+
chat = ChatOpenAI(
|
| 17 |
+
api_key=OKTA_ACCESS_TOKEN,
|
| 18 |
+
base_url=BASE_URL,
|
| 19 |
+
model="GPT_4_1",
|
| 20 |
+
default_headers={"Subscription-Key": SUBSCRIPTION_KEY},
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
duckduckgo = DuckDuckGoSearchRun()
|
| 24 |
+
python_repl = PythonREPL()
|
| 25 |
+
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
|
| 26 |
+
|
| 27 |
+
def prompt(state: AgentState, config: RunnableConfig) -> list[AnyMessage]:
|
| 28 |
+
file_path = config["configurable"].get("file_path", "")
|
| 29 |
+
system_msg = (
|
| 30 |
+
f"You are an AI assistant evaluated on the GAIA benchmark. "
|
| 31 |
+
f"Answer questions using only verified information. "
|
| 32 |
+
f"Use the available tools to find answers when needed. "
|
| 33 |
+
f"If you do not have enough information, reply: 'I do not have enough information to answer the question.' "
|
| 34 |
+
f"Provide only the direct answer, with no extra explanation, formatting, or restating the question. "
|
| 35 |
+
f"For example, if asked 'What is the capital of France?', answer 'Paris'. "
|
| 36 |
+
)
|
| 37 |
+
if file_path:
|
| 38 |
+
system_msg += f"If a file is referenced, use the file path: {file_path}."
|
| 39 |
+
return [{"role": "system", "content": system_msg}] + state["messages"]
|
| 40 |
+
|
| 41 |
+
react_agent = create_react_agent(
|
| 42 |
+
model=chat,
|
| 43 |
+
tools=[duckduckgo, wikipedia],
|
| 44 |
+
prompt=prompt,
|
| 45 |
+
)
|