devasurya commited on
Commit
11ac4ee
·
verified ·
1 Parent(s): 046cd4e

Update langgraph_agent.py

Browse files
Files changed (1) hide show
  1. langgraph_agent.py +16 -1
langgraph_agent.py CHANGED
@@ -67,6 +67,21 @@ def speech_to_text(audio_path: str) -> str:
67
  """
68
  return speech_to_text_tool(audio_path=audio_path)
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  def prompt(state: AgentState, config: RunnableConfig) -> list[AnyMessage]:
72
  file_path = config["configurable"].get("file_path", "")
@@ -84,6 +99,6 @@ def prompt(state: AgentState, config: RunnableConfig) -> list[AnyMessage]:
84
 
85
  react_agent = create_react_agent(
86
  model=chat,
87
- tools=[duckduckgo, wikipedia, visit_webpage, python_interpreter, speech_to_text],
88
  prompt=prompt,
89
  )
 
67
  """
68
  return speech_to_text_tool(audio_path=audio_path)
69
 
70
+ @tool
71
+ def read_file_contents(file_path: str) -> str:
72
+ """
73
+ Read and return the contents of a file as a string.
74
+ Args:
75
+ file_path (str): The path to the file to read.
76
+ Returns:
77
+ str: The contents of the file, or an error message if the file cannot be read.
78
+ """
79
+ try:
80
+ with open(file_path, 'r', encoding='utf-8') as f:
81
+ return f.read()
82
+ except Exception as e:
83
+ return f"Error reading file: {e}"
84
+
85
 
86
  def prompt(state: AgentState, config: RunnableConfig) -> list[AnyMessage]:
87
  file_path = config["configurable"].get("file_path", "")
 
99
 
100
  react_agent = create_react_agent(
101
  model=chat,
102
+ tools=[duckduckgo, wikipedia, visit_webpage, python_interpreter, speech_to_text, read_file_contents],
103
  prompt=prompt,
104
  )