You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prediction = agent(question="Which baseball team does Shohei Ohtani play for?")
38
+
prediction = agent(question="Which baseball team does Shohei Ohtani play for in June 2025?")
30
39
print(prediction.answer)
31
40
```
32
41
33
42
```
34
-
Shohei Ohtani plays for the Los Angeles Angels.
43
+
Shohei Ohtani is expected to play for the Hokkaido Nippon-Ham Fighters in June 2025, based on the available information.
35
44
```
36
45
37
-
Oh, this is incorrect. He no longer plays for the Angels; he moved to the Dodgers and won the World Series in 2024! Let's debug the program and explore potential fixes.
46
+
Oh, this is incorrect. He no longer plays for the Hokkaido Nippon-Ham Fighters; he moved to the Dodgers and won the World Series in 2024! Let's debug the program and explore potential fixes.
38
47
39
48
## Using ``inspect_history``
40
49
@@ -57,13 +66,16 @@ Your input fields are:
57
66
58
67
Response:
59
68
60
-
[[ ## Thought_5 ## ]]
61
-
The search results continue to be unhelpful and do not provide the current team for Shohei Ohtani in Major League Baseball. I need to conclude that he plays for the Los Angeles Angels based on prior knowledge, as the searches have not yielded updated information.
69
+
Response:
70
+
71
+
[[ ## reasoning ## ]]
72
+
The search for information regarding Shohei Ohtani's team in June 2025 did not yield any specific results. The retrieved data consistently mentioned that he plays for the Hokkaido Nippon-Ham Fighters, but there was no indication of any changes or updates regarding his team for the specified date. Given the lack of information, it is reasonable to conclude that he may still be with the Hokkaido Nippon-Ham Fighters unless there are future developments that are not captured in the current data.
62
73
63
-
[[ ## Action_5 ## ]]
64
-
Finish[Los Angeles Angels]
74
+
[[ ## answer ## ]]
75
+
Shohei Ohtani is expected to play for the Hokkaido Nippon-Ham Fighters in June 2025, based on the available information.
65
76
66
77
[[ ## completed ## ]]
78
+
67
79
```
68
80
The log reveals that the agent could not retrieve helpful information from the search tool. However, what exactly did the retriever return? While useful, `inspect_history` has some limitations:
69
81
@@ -81,40 +93,73 @@ The log reveals that the agent could not retrieve helpful information from the s
81
93
pip install -U mlflow>=2.18.0
82
94
```
83
95
96
+
After installation, spin up your server via the command below.
97
+
98
+
```
99
+
# It is highly recommended to use SQL store when using MLflow tracing
100
+
mlflow server --backend-store-uri sqlite:///mydb.sqlite
101
+
```
102
+
103
+
If you don't specify a different port via `--port` flag, you MLflow server will be hosted at port 5000.
104
+
105
+
Now let's change our code snippet to enable MLflow tracing. We need to:
106
+
107
+
- Tell MLflow where the server is hosted.
108
+
- Apply `mlflow.autolog()` so that DSPy tracing is automatically captured.
109
+
110
+
The full code is as below, now let's run it again!
agent(question="Which baseball team does Shohei Ohtani play for?")
97
-
```
98
128
99
-
MLflow automatically generates a **trace** for the prediction and records it in the experiment. To explore traces visually, launch the MLflow UI by the following command and access it in your browser:
129
+
defretrieve(query: str):
130
+
"""Retrieve top 3 relevant information from ColBert"""
print(agent(question="Which baseball team does Shohei Ohtani play for?"))
103
137
```
104
138
105
-

106
139
107
-
From the retriever step output, you can observe that it returned outdated information; indicating Shohei Ohtani was still playing in the Japanese league and the final answer was based on the LLM's prior knowledge! We should update the dataset or add additional tools to ensure access to the latest information.
140
+
MLflow automatically generates a **trace** for each prediction and records it within your experiment. To explore these traces visually, open `http://127.0.0.1:5000/`
141
+
in your browser, then select the experiment you just created and navigate to the Traces tab:
108
142
109
-
!!! info Learn more about MLflow
143
+

110
144
111
-
MLflow is an end-to-end LLMOps platform that offers extensive features like experiment tracking, evaluation, and deployment. To learn more about DSPy and MLflow integration, visit [this tutorial](../deployment/#deploying-with-mlflow).
145
+
Click on the most recent trace to view its detailed breakdown:
146
+
147
+

112
148
113
-
For example, we can add a web search capability to the agent, using the [Tavily](https://tavily.com/) web search API.
149
+
Here, you can examine the input and output of every step in your workflow. For example, the screenshot above shows the `retrieve` function's input and output. By inspecting the retriever's output, you can see that it returned outdated information, which is not sufficient to determine which team Shohei Ohtani plays for in June 2025. You can also inspect
150
+
other steps, e.g, anguage model's input, output, and configuration.
151
+
152
+
To address the issue of outdated information, you can replace the `retrieve` function with a web search tool powered by [Tavily search](https://www.tavily.com/).
For a complete guide on how to use MLflow tracing, please refer to
187
+
the [MLflow Tracing Guide](https://mlflow.org/docs/3.0.0rc0/tracing).
188
+
189
+
190
+
191
+
!!! info Learn more about MLflow
192
+
193
+
MLflow is an end-to-end LLMOps platform that offers extensive features like experiment tracking, evaluation, and deployment. To learn more about DSPy and MLflow integration, visit [this tutorial](../deployment/#deploying-with-mlflow).
194
+
136
195
137
196
## Building a Custom Logging Solution
138
197
@@ -145,7 +204,7 @@ Sometimes, you may want to implement a custom logging solution. For instance, yo
145
204
|`on_adapter_format_start` / `on_adapter_format_end`| Triggered when a `dspy.Adapter` subclass formats the input prompt. |
146
205
|`on_adapter_parse_start` / `on_adapter_parse_end`| Triggered when a `dspy.Adapter` subclass postprocess the output text from an LM. |
147
206
148
-
Here’s an example of custom callback that logs the intermediate steps of a ReAct agent:
207
+
Here's an example of custom callback that logs the intermediate steps of a ReAct agent:
Be cautious when working with input or output data in callbacks. Mutating them in-place can modify the original data passed to the program, potentially leading to unexpected behavior. To avoid this, it’s strongly recommended to create a copy of the data before performing any operations that may alter it.
245
+
Be cautious when working with input or output data in callbacks. Mutating them in-place can modify the original data passed to the program, potentially leading to unexpected behavior. To avoid this, it's strongly recommended to create a copy of the data before performing any operations that may alter it.
0 commit comments