Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Updates to multi-agent notebook

Omar Khattab1a0feb68c230
diff --git a/examples/agents/multi_agent.ipynb b/examples/agents/multi_agent.ipynb
index 7678cfbd1..533047976 100644
--- a/examples/agents/multi_agent.ipynb
+++ b/examples/agents/multi_agent.ipynb
@@ -324,8 +324,6 @@
}
],
"source": [
- "from dspy.teleprompt import BootstrapFewShotWithRandomSearch\n",
- "\n",
"config = dict(max_bootstrapped_demos=2, max_labeled_demos=0, num_candidate_programs=20, num_threads=8)\n",
"tp = BootstrapFewShotWithRandomSearch(metric=dspy.evaluate.answer_exact_match, **config)\n",
"optimized_react = tp.compile(agent, trainset=trainset, valset=valset)"
@@ -835,6 +833,37 @@
"\n",
"To keep the current release super quick, Omar will extend this notebook into an annotated version if there's significant interest."
]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 8) Post-Conclusion Note.\n",
+ "\n",
+ "With a little bit of syntactic sugar, the main code in this notebook could be as short as 10 lines excluding whitespace:\n",
+ "\n",
+ "```python\n",
+ "agent = dspy.ReAct(\"question -> answer\", tools=[dspy.Retrieve(k=1)])\n",
+ "\n",
+ "optimizer = BootstrapFewShotWithRandomSearch(metric=dspy.evaluate.answer_exact_match)\n",
+ "optimized_react = optimizer.compile(agent, trainset=trainset, valset=valset)\n",
+ "\n",
+ "class Aggregator(dspy.Module):\n",
+ "\tdef __init__(self):\n",
+ "\t\tself.aggregate = dspy.ChainOfThought('context, question -> answer')\n",
+ "\n",
+ "\tdef forward(self, question):\n",
+ " preds = [agent(question=question) for agent in optimized_react.best_programs[:5]]\n",
+ "\t\treturn self.aggregate(context=deduplicate(flatten([p.observations for p in preds])), question=question)\n",
+ "\t\n",
+ "optimized_aggregator = optimizer.compile(aggregator, trainset=trainset, valset=valset)\n",
+ "```"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": []
}
],
"metadata": {