AGiorni commited on
Commit
148189b
·
1 Parent(s): e517812

fixed bugs

Browse files
.env CHANGED
@@ -4,6 +4,6 @@ AZURE_OPENAI_DEPLOYMENT_NAME = "gpt-4o"
4
  OPENAI_API_VERSION = "2025-04-01-preview"
5
 
6
  # Get keys for your project from the project settings page: https://cloud.langfuse.com
7
- LANGFUSE_PUBLIC_KEY = "pk-lf-7eab47cc-6608-4d4d-95e9-1e830b60b9e9"
8
- LANGFUSE_SECRET_KEY = "sk-lf-438ec200-3367-425a-8283-4f858ba924f1"
9
  LANGFUSE_HOST = "https://cloud.langfuse.com" # 🇪🇺 EU region
 
4
  OPENAI_API_VERSION = "2025-04-01-preview"
5
 
6
  # Get keys for your project from the project settings page: https://cloud.langfuse.com
7
+ LANGFUSE_PUBLIC_KEY = "pk-lf-61f55889-2dd2-47a1-ab49-99c60b7ddb40"
8
+ LANGFUSE_SECRET_KEY = "sk-lf-632ab357-d225-421f-9f75-7f6685960c50"
9
  LANGFUSE_HOST = "https://cloud.langfuse.com" # 🇪🇺 EU region
__pycache__/main_agent.cpython-313.pyc CHANGED
Binary files a/__pycache__/main_agent.cpython-313.pyc and b/__pycache__/main_agent.cpython-313.pyc differ
 
__pycache__/prompts_lib.cpython-313.pyc CHANGED
Binary files a/__pycache__/prompts_lib.cpython-313.pyc and b/__pycache__/prompts_lib.cpython-313.pyc differ
 
__pycache__/tools.cpython-313.pyc CHANGED
Binary files a/__pycache__/tools.cpython-313.pyc and b/__pycache__/tools.cpython-313.pyc differ
 
app.py CHANGED
@@ -23,7 +23,7 @@ class BasicAgent:
23
 
24
  response = main_agent.agent.invoke({'messages': message})
25
 
26
- answer = response.get('messages')[1].content
27
 
28
  # fixed_answer = "This is a default answer."
29
  print(f"Agent returning answer: {answer}")
 
23
 
24
  response = main_agent.agent.invoke({'messages': message})
25
 
26
+ answer = response.get('messages')[-1].content
27
 
28
  # fixed_answer = "This is a default answer."
29
  print(f"Agent returning answer: {answer}")
main_agent.py CHANGED
@@ -33,13 +33,13 @@ tools = [duckduck_tool]
33
  chat_w_tools = llm.bind_tools(tools)
34
 
35
  # load system prompt
36
- system_prompt = my_prompts.system_prompt
37
  system_message = SystemMessage(content=system_prompt)
38
 
39
  # define nodes
40
  def assistant(state: State):
41
  return {
42
- "messages": [llm.invoke(state["messages"])]
43
  }
44
 
45
 
@@ -52,7 +52,8 @@ builder.add_node("tools", ToolNode(tools))
52
 
53
  # define edges
54
  builder.add_edge(START, "assistant")
55
- builder.add_conditional_edges("assistant", tools_condition)
 
56
  builder.add_edge("tools", "assistant")
57
  # compile gtaph
58
  agent = builder.compile()
 
33
  chat_w_tools = llm.bind_tools(tools)
34
 
35
  # load system prompt
36
+ system_prompt = my_prompts.system_prompt2
37
  system_message = SystemMessage(content=system_prompt)
38
 
39
  # define nodes
40
  def assistant(state: State):
41
  return {
42
+ "messages": [chat_w_tools.invoke([system_message] + state["messages"])]
43
  }
44
 
45
 
 
52
 
53
  # define edges
54
  builder.add_edge(START, "assistant")
55
+ builder.add_conditional_edges("assistant", tools_condition,
56
+ {"tools": "tools", "__end__": "__end__"})
57
  builder.add_edge("tools", "assistant")
58
  # compile gtaph
59
  agent = builder.compile()
prompts_lib.py CHANGED
@@ -17,7 +17,8 @@ Report just YOUR FINAL ANSWER.
17
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated
18
  list of numbers and/or strings.
19
  If you are asked for a number, don’t use comma to write your number neither use units such as $ or
20
- percent sign unless specified otherwise.
 
21
  If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the
22
  digits in plain text unless specified otherwise.
23
  If you are asked for a comma separated list, apply the above rules depending of whether the element
 
17
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated
18
  list of numbers and/or strings.
19
  If you are asked for a number, don’t use comma to write your number neither use units such as $ or
20
+ percent sign unless specified otherwise. For example, if you are asked "how many ... ecc. ...?"
21
+ you should answer with a number.
22
  If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the
23
  digits in plain text unless specified otherwise.
24
  If you are asked for a comma separated list, apply the above rules depending of whether the element
test.ipynb CHANGED
@@ -14,7 +14,7 @@
14
  },
15
  {
16
  "cell_type": "code",
17
- "execution_count": 3,
18
  "id": "bbd5b78b",
19
  "metadata": {},
20
  "outputs": [],
@@ -25,39 +25,50 @@
25
  },
26
  {
27
  "cell_type": "code",
28
- "execution_count": 5,
29
- "id": "76d480cd",
30
  "metadata": {},
31
  "outputs": [],
32
  "source": [
33
- "message = pl.system_prompt2 + 'How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?'"
 
 
 
 
 
 
 
 
 
34
  ]
35
  },
36
  {
37
  "cell_type": "code",
38
- "execution_count": 18,
39
  "id": "e097a098",
40
  "metadata": {},
41
  "outputs": [],
42
  "source": [
43
- "from langfuse.langchain import CallbackHandler\n",
44
- "\n",
45
- "# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)\n",
46
- "langfuse_handler = CallbackHandler()\n",
47
- "langfuse_handler2 = CallbackHandler()\n",
48
  "\n",
49
  "class BasicAgent:\n",
50
  " def __init__(self):\n",
51
  " self.agent = ma.agent\n",
 
52
  " def __call__(self, question: str) -> str:\n",
53
  " print(f\"Agent received question (first 50 chars): {question[:50]}...\")\n",
54
  "\n",
55
- " message = pl.system_prompt2 + question\n",
 
 
 
 
 
 
 
 
 
56
  "\n",
57
- " response = self.agent.invoke(\n",
58
- " input={'messages': message},\n",
59
- " config={\"callbacks\": [langfuse_handler2]}\n",
60
- " )\n",
61
  "\n",
62
  " answer = response.get('messages')[1].content\n",
63
  "\n",
@@ -68,7 +79,7 @@
68
  },
69
  {
70
  "cell_type": "code",
71
- "execution_count": 19,
72
  "id": "af68a6a5",
73
  "metadata": {},
74
  "outputs": [],
@@ -78,7 +89,7 @@
78
  },
79
  {
80
  "cell_type": "code",
81
- "execution_count": 20,
82
  "id": "02c87f0c",
83
  "metadata": {},
84
  "outputs": [
@@ -86,13 +97,117 @@
86
  "name": "stdout",
87
  "output_type": "stream",
88
  "text": [
89
- "Agent received question (first 50 chars): How many studio albums were published by Mercedes ...\n",
90
- "Agent returning answer: Seven\n"
 
91
  ]
92
  }
93
  ],
94
  "source": [
95
- "answer = agent(\"How many studio albums were published by Mercedes Sousa between 2000 and 2009 included? use duckduckgo tool you have available to search wikipedia to respond\")"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  ]
97
  },
98
  {
@@ -100,6 +215,85 @@
100
  "execution_count": null,
101
  "id": "7f82cd74",
102
  "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  "outputs": [],
104
  "source": []
105
  }
 
14
  },
15
  {
16
  "cell_type": "code",
17
+ "execution_count": 2,
18
  "id": "bbd5b78b",
19
  "metadata": {},
20
  "outputs": [],
 
25
  },
26
  {
27
  "cell_type": "code",
28
+ "execution_count": null,
29
+ "id": "9d00e0ae",
30
  "metadata": {},
31
  "outputs": [],
32
  "source": [
33
+ "from langfuse import Langfuse\n",
34
+ "from langfuse.langchain import CallbackHandler\n",
35
+ "\n",
36
+ "langfuse = Langfuse(\n",
37
+ " public_key=\"pk-lf-61f55889-2dd2-47a1-ab49-99c60b7ddb40\",\n",
38
+ " secret_key=\"sk-lf-632ab357-d225-421f-9f75-7f6685960c50\",\n",
39
+ " host=\"https://cloud.langfuse.com\"\n",
40
+ ")\n",
41
+ "\n",
42
+ "langfuse_handler = CallbackHandler()"
43
  ]
44
  },
45
  {
46
  "cell_type": "code",
47
+ "execution_count": 11,
48
  "id": "e097a098",
49
  "metadata": {},
50
  "outputs": [],
51
  "source": [
52
+ "logfuse = False\n",
 
 
 
 
53
  "\n",
54
  "class BasicAgent:\n",
55
  " def __init__(self):\n",
56
  " self.agent = ma.agent\n",
57
+ " self.responses = []\n",
58
  " def __call__(self, question: str) -> str:\n",
59
  " print(f\"Agent received question (first 50 chars): {question[:50]}...\")\n",
60
  "\n",
61
+ " # message = pl.system_prompt2 + question\n",
62
+ " if logfuse:\n",
63
+ " response = self.agent.invoke(\n",
64
+ " input={'messages': question},\n",
65
+ " config={\"callbacks\": [langfuse_handler]}\n",
66
+ " )\n",
67
+ " else:\n",
68
+ " response = self.agent.invoke(input={'messages': question})\n",
69
+ " \n",
70
+ " self.responses.append(response)\n",
71
  "\n",
 
 
 
 
72
  "\n",
73
  " answer = response.get('messages')[1].content\n",
74
  "\n",
 
79
  },
80
  {
81
  "cell_type": "code",
82
+ "execution_count": 12,
83
  "id": "af68a6a5",
84
  "metadata": {},
85
  "outputs": [],
 
89
  },
90
  {
91
  "cell_type": "code",
92
+ "execution_count": 13,
93
  "id": "02c87f0c",
94
  "metadata": {},
95
  "outputs": [
 
97
  "name": "stdout",
98
  "output_type": "stream",
99
  "text": [
100
+ "Agent received question (first 50 chars): \n",
101
+ "How many studio albums were published by Mercedes...\n",
102
+ "Agent returning answer: \n"
103
  ]
104
  }
105
  ],
106
  "source": [
107
+ "question = \"\"\"\n",
108
+ "How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\n",
109
+ " use duckduckgo tool you have available to search wikipedia to respond\n",
110
+ "\"\"\"\n",
111
+ "\n",
112
+ "question = \"\"\"\n",
113
+ "How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\n",
114
+ "you can use the latest 2022 version of the english wikipedia\n",
115
+ "\"\"\"\n",
116
+ "\n",
117
+ "answer = agent(question)"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": 15,
123
+ "id": "aef6eef2",
124
+ "metadata": {},
125
+ "outputs": [
126
+ {
127
+ "data": {
128
+ "text/plain": [
129
+ "1"
130
+ ]
131
+ },
132
+ "execution_count": 15,
133
+ "metadata": {},
134
+ "output_type": "execute_result"
135
+ }
136
+ ],
137
+ "source": [
138
+ "len(agent.responses)"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": 20,
144
+ "id": "a067f206",
145
+ "metadata": {},
146
+ "outputs": [
147
+ {
148
+ "data": {
149
+ "text/plain": [
150
+ "[HumanMessage(content='\\nHow many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\\nyou can use the latest 2022 version of the english wikipedia\\n', additional_kwargs={}, response_metadata={}, id='fd6395c5-f87b-4ded-83b5-02e7eed41f84'),\n",
151
+ " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_wvcdxWEk8P0BX8iwCXkfFpDP', 'function': {'arguments': '{\"__arg1\":\"Mercedes Sosa studio albums 2000 to 2009 site:en.wikipedia.org\"}', 'name': 'duckduckgo_search'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 36, 'prompt_tokens': 271, 'total_tokens': 307, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFusZ9dXozBGmKrkuACf3ZtbIeoNC', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'tool_calls', 'logprobs': None, 'content_filter_results': {}}, id='run--5581304b-78fc-4b39-add7-de8d5554c1e8-0', tool_calls=[{'name': 'duckduckgo_search', 'args': {'__arg1': 'Mercedes Sosa studio albums 2000 to 2009 site:en.wikipedia.org'}, 'id': 'call_wvcdxWEk8P0BX8iwCXkfFpDP', 'type': 'tool_call'}], usage_metadata={'input_tokens': 271, 'output_tokens': 36, 'total_tokens': 307, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}),\n",
152
+ " ToolMessage(content='The 10th Annual Latin Grammy Awards took place on Thursday, November 5, 2009 , at the Mandalay Bay Events Center in Las Vegas, Nevada. This was the second time the show took place in Las Vegas. Juan Gabriel was honored as the Latin Recording Academy P... Shakira performing \"Don\\'t Bother\" at Rock in Rio in 2008. The Colombian singer Shakira has recorded songs for twelve studio albums , three compilation albums , two live albums and two promotional albums . The album was recorded in Buenos Aires, Argentina, In the first phase, double bass, violin, bandoneon, guitar and piano were recorded, then strings orchestra under the direction of Alejandro Terán.Adrián Sosa . Studio albums . Bajofondo Tango Club. Mar dulce. 1000 Hurts is the third studio album by American rock band Shellac, released on August 8, 2000 . In its official promotional materials Shellac jokingly described this album as follows: \"There are no 12-minute songs on this one. This record is mor... The discography of the post-hardcore band ...And You Will Know Us by the Trail of Dead consists of 11 studio albums , one live album , 22 singles, five EPs and 25 music videos. Albums . Studio albums . Live albums . Extended plays. Split EPs. Singles. Oth...', name='duckduckgo_search', id='8c1c55dc-d10f-4dba-848f-2f2a0ec3de64', tool_call_id='call_wvcdxWEk8P0BX8iwCXkfFpDP'),\n",
153
+ " AIMessage(content='2', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 3, 'prompt_tokens': 597, 'total_tokens': 600, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFuscjskeYhun2hoXrOtB5JiYmUSI', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'stop', 'logprobs': None, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}, id='run--6e8c9956-0bc1-4457-9e07-4ff9e9ea6104-0', usage_metadata={'input_tokens': 597, 'output_tokens': 3, 'total_tokens': 600, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]"
154
+ ]
155
+ },
156
+ "execution_count": 20,
157
+ "metadata": {},
158
+ "output_type": "execute_result"
159
+ }
160
+ ],
161
+ "source": [
162
+ "agent.responses[0].get('messages')"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 21,
168
+ "id": "8cb9b3e1",
169
+ "metadata": {},
170
+ "outputs": [
171
+ {
172
+ "data": {
173
+ "text/plain": [
174
+ "{langchain_core.messages.human.HumanMessage: '\\nHow many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\\nyou can use the latest 2022 version of the english wikipedia\\n',\n",
175
+ " langchain_core.messages.ai.AIMessage: '2',\n",
176
+ " langchain_core.messages.tool.ToolMessage: 'The 10th Annual Latin Grammy Awards took place on Thursday, November 5, 2009 , at the Mandalay Bay Events Center in Las Vegas, Nevada. This was the second time the show took place in Las Vegas. Juan Gabriel was honored as the Latin Recording Academy P... Shakira performing \"Don\\'t Bother\" at Rock in Rio in 2008. The Colombian singer Shakira has recorded songs for twelve studio albums , three compilation albums , two live albums and two promotional albums . The album was recorded in Buenos Aires, Argentina, In the first phase, double bass, violin, bandoneon, guitar and piano were recorded, then strings orchestra under the direction of Alejandro Terán.Adrián Sosa . Studio albums . Bajofondo Tango Club. Mar dulce. 1000 Hurts is the third studio album by American rock band Shellac, released on August 8, 2000 . In its official promotional materials Shellac jokingly described this album as follows: \"There are no 12-minute songs on this one. This record is mor... The discography of the post-hardcore band ...And You Will Know Us by the Trail of Dead consists of 11 studio albums , one live album , 22 singles, five EPs and 25 music videos. Albums . Studio albums . Live albums . Extended plays. Split EPs. Singles. Oth...'}"
177
+ ]
178
+ },
179
+ "execution_count": 21,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "{type(m): m.content for m in agent.responses[0].get('messages')}"
186
+ ]
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "execution_count": 23,
191
+ "id": "069db350",
192
+ "metadata": {},
193
+ "outputs": [
194
+ {
195
+ "name": "stdout",
196
+ "output_type": "stream",
197
+ "text": [
198
+ "<class 'langchain_core.messages.human.HumanMessage'>: \n",
199
+ "How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\n",
200
+ "you can use the latest 2022 version of the english wikipedia\n",
201
+ "\n",
202
+ "<class 'langchain_core.messages.ai.AIMessage'>: \n",
203
+ "<class 'langchain_core.messages.tool.ToolMessage'>: The 10th Annual Latin Grammy Awards took place on Thursday, November 5, 2009 , at the Mandalay Bay Events Center in Las Vegas, Nevada. This was the second time the show took place in Las Vegas. Juan Gabriel was honored as the Latin Recording Academy P... Shakira performing \"Don't Bother\" at Rock in Rio in 2008. The Colombian singer Shakira has recorded songs for twelve studio albums , three compilation albums , two live albums and two promotional albums . The album was recorded in Buenos Aires, Argentina, In the first phase, double bass, violin, bandoneon, guitar and piano were recorded, then strings orchestra under the direction of Alejandro Terán.Adrián Sosa . Studio albums . Bajofondo Tango Club. Mar dulce. 1000 Hurts is the third studio album by American rock band Shellac, released on August 8, 2000 . In its official promotional materials Shellac jokingly described this album as follows: \"There are no 12-minute songs on this one. This record is mor... The discography of the post-hardcore band ...And You Will Know Us by the Trail of Dead consists of 11 studio albums , one live album , 22 singles, five EPs and 25 music videos. Albums . Studio albums . Live albums . Extended plays. Split EPs. Singles. Oth...\n",
204
+ "<class 'langchain_core.messages.ai.AIMessage'>: 2\n"
205
+ ]
206
+ }
207
+ ],
208
+ "source": [
209
+ "for m in agent.responses[0].get('messages'):\n",
210
+ " print(f'{type(m)}: {m.content}')"
211
  ]
212
  },
213
  {
 
215
  "execution_count": null,
216
  "id": "7f82cd74",
217
  "metadata": {},
218
+ "outputs": [
219
+ {
220
+ "name": "stdout",
221
+ "output_type": "stream",
222
+ "text": [
223
+ "========================================\n",
224
+ "Current Node: {'assistant': {'messages': [AIMessage(content='I currently don\\'t have access to live tools like DuckDuckGo or the internet to perform searches. However, I can provide information based on my existing knowledge. Could you clarify if you meant \"Mercedes Sosa,\" the famous Argentine singer? If so, I can help you with her discography details based on my knowledge. Let me know!', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 69, 'prompt_tokens': 42, 'total_tokens': 111, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFtQQV0iFj7IB32vT0dZP4GQXBCTa', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'stop', 'logprobs': None, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}, id='run--e8e035c3-0fe0-45d3-b628-be9d0446b44b-0', usage_metadata={'input_tokens': 42, 'output_tokens': 69, 'total_tokens': 111, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
225
+ ]
226
+ }
227
+ ],
228
+ "source": [
229
+ "message = pl.system_prompt2 + 'How many studio albums were published by Mercedes Sousa between 2000 and 2009 included? use the duckduckgo toll you have available to answer the question'\n",
230
+ "# message = 'How many studio albums were published by Mercedes Sousa between 2000 and 2009 included? use the duckduckgo toll you have available to answer the question'\n",
231
+ "\n",
232
+ "message = \"\"\"\n",
233
+ "use the duckduckgo tool you have available to search wikipedia to respond:\n",
234
+ " How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\"\n",
235
+ "\n",
236
+ "\"\"\"\n",
237
+ "\n",
238
+ "\n",
239
+ "for step in ma.agent.stream(\n",
240
+ " {\"messages\": [{\"role\": \"user\", \"content\": message}]}, \n",
241
+ " config={\"callbacks\": [langfuse_handler]}\n",
242
+ " ):\n",
243
+ " print(\"=\"*40)\n",
244
+ " print(\"Current Node:\", step)"
245
+ ]
246
+ },
247
+ {
248
+ "cell_type": "code",
249
+ "execution_count": 7,
250
+ "id": "0030db17",
251
+ "metadata": {},
252
+ "outputs": [
253
+ {
254
+ "name": "stdout",
255
+ "output_type": "stream",
256
+ "text": [
257
+ "========================================\n",
258
+ "Current Node: {'assistant': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_f9Sfgby4vg1UrtW8YynmOhWM', 'function': {'arguments': '{\"__arg1\":\"Mercedes Sosa studio albums published between 2000 and 2009\"}', 'name': 'duckduckgo_search'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 33, 'prompt_tokens': 241, 'total_tokens': 274, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFtm4zDyVSV0wDRH7nFVj6iy3TZvi', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'tool_calls', 'logprobs': None, 'content_filter_results': {}}, id='run--7384da15-be31-40b0-a227-a7ad44f02fd5-0', tool_calls=[{'name': 'duckduckgo_search', 'args': {'__arg1': 'Mercedes Sosa studio albums published between 2000 and 2009'}, 'id': 'call_f9Sfgby4vg1UrtW8YynmOhWM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 241, 'output_tokens': 33, 'total_tokens': 274, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
259
+ "========================================\n",
260
+ "Current Node: {'tools': {'messages': [ToolMessage(content='Shakira performing \"Don\\'t Bother\" at Rock in Rio in 2008. The Colombian singer Shakira has recorded songs for twelve studio albums , three compilation albums , two live albums and two promotional albums . A blend of luxury, sportiness & performance. Be it Saloon, Estate, Coupé, Cabriolet, Roadster, SUV & more. Experience the products from Mercedes-Benz. Please submit the information above by clicking \"SEND MESSAGE\" below. Thank you for the information provided. Please visit GTLS to see the C-Program courses available and enrol … Explore the Mercedes-Benz GLE: a luxury SUV offering modern comfort, innovative technology, and dynamic design. Cap, Special Edition George Russell, VINTAGE FIND, Mercedes-AMG F1', name='duckduckgo_search', id='866d2392-5d2d-4510-8c30-64fb41d85ed5', tool_call_id='call_f9Sfgby4vg1UrtW8YynmOhWM')]}}\n",
261
+ "========================================\n",
262
+ "Current Node: {'assistant': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_iIbkHozCJUs2O4uwuqtjfnkL', 'function': {'arguments': '{\"__arg1\":\"list of Mercedes Sosa studio albums 2000 to 2009\"}', 'name': 'duckduckgo_search'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 33, 'prompt_tokens': 435, 'total_tokens': 468, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFtm7oWPTbseqaMDBT8VvVJrVOj0G', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'tool_calls', 'logprobs': None, 'content_filter_results': {}}, id='run--67e26704-1656-4deb-889b-10478209523f-0', tool_calls=[{'name': 'duckduckgo_search', 'args': {'__arg1': 'list of Mercedes Sosa studio albums 2000 to 2009'}, 'id': 'call_iIbkHozCJUs2O4uwuqtjfnkL', 'type': 'tool_call'}], usage_metadata={'input_tokens': 435, 'output_tokens': 33, 'total_tokens': 468, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
263
+ "========================================\n",
264
+ "Current Node: {'tools': {'messages': [ToolMessage(content=\"Her career spanned four decades and she was the recipient of six Latin Grammy awards ( 2000 , 2003, 2004, 2006, 2009 , 2011), including a Latin Grammy Lifetime Achievement Award in 2004 and two posthumous Latin Grammy Award for Best Folk Album in 2009 and 2011. Full list of Mercedes Sosa albums , sorted by release date. You can also sort the list of albums by most recently added, year recorded (from most recent to first recorded), by views and by album name. Explore Mercedes Sosa ' s biography, discography, and artist credits. Shop rare vinyl records, top albums , and more on Discogs. Apr 29, 2009 · See all of Mercedes Sosa ’ s albums on Genius. Information on Mercedes Sosa . Complete discography , ratings, reviews and more.\", name='duckduckgo_search', id='072c90cf-71d7-4332-93fd-bafd1239a526', tool_call_id='call_iIbkHozCJUs2O4uwuqtjfnkL')]}}\n",
265
+ "========================================\n",
266
+ "Current Node: {'assistant': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Pa9Gvj8vwo47ksolMBkVSbX9', 'function': {'arguments': '{\"__arg1\":\"Mercedes Sosa discography\"}', 'name': 'duckduckgo_search'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 24, 'prompt_tokens': 658, 'total_tokens': 682, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFtmBUriykWlacE7pkuorSIKeG8mZ', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'tool_calls', 'logprobs': None, 'content_filter_results': {}}, id='run--f823a193-a60f-4fb0-bd06-e226dd419899-0', tool_calls=[{'name': 'duckduckgo_search', 'args': {'__arg1': 'Mercedes Sosa discography'}, 'id': 'call_Pa9Gvj8vwo47ksolMBkVSbX9', 'type': 'tool_call'}], usage_metadata={'input_tokens': 658, 'output_tokens': 24, 'total_tokens': 682, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
267
+ "========================================\n",
268
+ "Current Node: {'tools': {'messages': [ToolMessage(content='Throughout the decade, she released albums such as Hasta la Victoria in 1972 and Traigo un Pueblo en mi Voz in 1973. Mercedes Sosa ... MERCEDES SOSA Corazón Libre ... Start / Artists / Mercedes Sosa / Discography / Mercedes Sosa y Horacio Guarany (single 1973) ... Home View Book Life & Career Politics Discography Discoveries Author Foundation Press Lieder und Episoden aus Mercedes Sosa - Die Stimme der Hoffnung (chronologisch) ... Startseite Das Buch Leben & Karriere Politik Discographie ... Mercedes Sosa y Horacio Guarany (single 1973) ... Şarkılar ve Bölümler, Mercedes Sosa -Umudun Sesinden( kronolojik)', name='duckduckgo_search', id='dcb0c53f-798b-4c38-8af8-a5cba66be5e6', tool_call_id='call_Pa9Gvj8vwo47ksolMBkVSbX9')]}}\n",
269
+ "========================================\n",
270
+ "Current Node: {'assistant': {'messages': [AIMessage(content='Cantora 1, Cantora 2, Corazón Libre', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 15, 'prompt_tokens': 841, 'total_tokens': 856, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-11-20', 'system_fingerprint': 'fp_ee1d74bde0', 'id': 'chatcmpl-CFtmHkRhyIq45cFhKc33aP6oNcJKN', 'service_tier': None, 'prompt_filter_results': [{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}], 'finish_reason': 'stop', 'logprobs': None, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}, id='run--e0b0be3a-98c4-4a6a-8b8f-9e83a937ede2-0', usage_metadata={'input_tokens': 841, 'output_tokens': 15, 'total_tokens': 856, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
271
+ ]
272
+ }
273
+ ],
274
+ "source": [
275
+ "message = \"\"\"\n",
276
+ "use the duckduckgo tool you have available to search wikipedia to respond:\n",
277
+ " How many studio albums were published by Mercedes Sousa between 2000 and 2009 included?\"\n",
278
+ "\n",
279
+ "\"\"\"\n",
280
+ "\n",
281
+ "message = pl.system_prompt2 + 'How many studio albums were published by Mercedes Sousa between 2000 and 2009 included? use the duckduckgo tool you have available to answer the question'\n",
282
+ "\n",
283
+ "\n",
284
+ "for step in ma.agent.stream(\n",
285
+ " {\"messages\": [{\"role\": \"user\", \"content\": message}]},\n",
286
+ " config={\"callbacks\": [langfuse_handler]}\n",
287
+ " ):\n",
288
+ " print(\"=\"*40)\n",
289
+ " print(\"Current Node:\", step)"
290
+ ]
291
+ },
292
+ {
293
+ "cell_type": "code",
294
+ "execution_count": null,
295
+ "id": "d57e9368",
296
+ "metadata": {},
297
  "outputs": [],
298
  "source": []
299
  }
tools.py CHANGED
@@ -1,4 +1,9 @@
1
  from langchain_community.tools import DuckDuckGoSearchRun
 
2
 
3
 
4
- duckduck_tool = DuckDuckGoSearchRun()
 
 
 
 
 
1
  from langchain_community.tools import DuckDuckGoSearchRun
2
+ from langchain.tools import Tool
3
 
4
 
5
+ duckduck_tool = Tool(
6
+ name="duckduckgo_search",
7
+ func=DuckDuckGoSearchRun(),
8
+ description="Searches DuckDuckGo for information from the web."
9
+ )