Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output handlers docs #53

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/source/basic_api.nblink

This file was deleted.

3 changes: 2 additions & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Examples

examples/blog_with_images
examples/research_agent
examples/output_handlers
examples/validating_agent_output
examples/advanced_output_handling
autogen
3 changes: 3 additions & 0 deletions docs/source/examples/advanced_output_handling.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/Advanced output handling.ipynb"
}
3 changes: 0 additions & 3 deletions docs/source/examples/output_handlers.nblink

This file was deleted.

3 changes: 3 additions & 0 deletions docs/source/examples/validating_agent_output.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/Validating agent output.ipynb"
}
566 changes: 566 additions & 0 deletions examples/Advanced output handling.ipynb

Large diffs are not rendered by default.

102 changes: 0 additions & 102 deletions examples/Basic introduction.ipynb

This file was deleted.

2 changes: 1 addition & 1 deletion examples/Multi-step research agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
9 changes: 8 additions & 1 deletion examples/Quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
"\n",
"Motleycrew also supports **delegation**: you can simply give any agent as a tool to any other agent. \n",
"\n",
"All the wrappers for tools and agents implement the Runnable interface, so you can use them as-is in LCEL and Langgraph code."
"All the wrappers for tools and agents implement the Runnable interface, so you can use them as-is in LCEL and Langgraph code.\n",
"\n",
"\n",
"### Output handlers\n",
"\n",
"An **output handler** is a special tool that the agent uses for submitting the final output instead of returning it raw. Besides defining a schema for the output, the output handler enables you to implement any validation logic inside it, including agent-based. If your agent returns invalid output, you can raise an exception that will be returned to the agent so that it can retry.\n",
"\n",
"See our usage examples with a [simple validator](examples/validating_agent_output.html) and an [advanced output handler with multiple fields](examples/advanced_output_handling.html).\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@
],
"source": [
"from IPython.display import display, Markdown\n",
"display(Markdown(task.output[\"checked_output\"]))"
"\n",
"final_result = task.output[\"checked_output\"]\n",
"display(Markdown(final_result))"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion motleycrew/agents/output_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from abc import ABC, abstractmethod
from langchain_core.tools import StructuredTool, BaseTool
from langchain_core.tools import StructuredTool
from langchain_core.pydantic_v1 import BaseModel

from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n swapped = False\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n swapped = True\n if not swapped:\n break\n return arr\n\n# Test the bubble sort function\nsample_array = [64, 34, 25, 12, 22, 11, 90]\nsorted_array = bubble_sort(sample_array)\nprint(sorted_array)\n\nThe `bubble_sort` function sorts an array using the bubble sort algorithm. It works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order. This process is repeated until the list is sorted. The outer loop runs `n` times, where `n` is the length of the array, and the inner loop runs `n-i-1` times to avoid re-checking the already sorted elements. An optimization is added by using a `swapped` flag to detect if any swaps were made during an iteration. If no swaps were made, the array is already sorted, and the algorithm can terminate early. The test case demonstrates the function by sorting a sample array."
1 change: 1 addition & 0 deletions tests/itest_golden_data/validating_agent_output_ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"## Comprehensive Analysis of AI Advancements in 2024\n\n### Key Trends in AI\n\n1. **Generative AI Adoption**:\n - Generative AI tools like ChatGPT have reached mass adoption, significantly impacting various industries. In 2024, organizations are not only adopting generative AI but also deriving substantial business value from it. This trend is expected to continue, with more people and businesses utilizing generative AI models for diverse applications.\n\n2. **Multimodal AI**:\n - Multimodal AI, which processes multiple input types such as text, images, and sound, is gaining traction. This approach mimics the human ability to process diverse sensory information and is expected to lead to more sophisticated AI applications.\n\n3. **Smaller and Open Source Models**:\n - There is a shift towards smaller language models and open-source advancements. These models are becoming more accessible, allowing for customized local models and data pipelines. This trend is democratizing AI, making it more available to smaller organizations and individual developers.\n\n4. **Model Optimization**:\n - Model optimization is becoming more accessible, addressing issues like GPU shortages and cloud costs. This trend is crucial for making AI more efficient and cost-effective.\n\n5. **Transfer Learning**:\n - Transfer learning, which uses preexisting models as a starting point for new tasks, is reducing the time and data needed to develop accurate models. This trend is expected to create new job opportunities focused on developing and maintaining these models.\n\n### Breakthrough Technologies\n\n1. **Advanced Generative AI Models**:\n - State-of-the-art generative AI models are becoming more useful for non-tech individuals. This democratization of AI technology is expected to lead to widespread experimentation and innovation.\n\n2. **Claude by Anthropic**:\n - Anthropic, founded by former OpenAI executives, has made significant strides with its large language model, Claude. This model is expected to compete with other leading AI technologies and drive further advancements in the field.\n\n3. **AI in Business Operations**:\n - AI is driving significant reductions in operational expenses, with businesses expecting a 37% reduction in costs in 2024. This is due to AI's ability to lower error rates and improve efficiency.\n\n### Potential Industry Impacts\n\n1. **Economic Transformation**:\n - 2024 is expected to be a pivotal year for AI, with generative AI triggering a metamorphosis across the global economic landscape. Businesses are waking up to the broad potential of AI, leading to transformative changes in various sectors.\n\n2. **Job Market Evolution**:\n - The rise of AI technologies is creating new job opportunities, particularly in developing, maintaining, and optimizing AI models. However, it may also lead to job displacement in certain sectors, necessitating a focus on reskilling and upskilling the workforce.\n\n3. **Environmental and Political Impacts**:\n - The adoption of AI is expected to have significant environmental and political impacts. For instance, AI can contribute to more efficient resource management and decision-making processes, but it also raises concerns about data privacy and ethical considerations.\n\n4. **Industry-Specific Applications**:\n - Different industries are adopting AI at varying rates. For example, sectors like healthcare, finance, and manufacturing are seeing substantial AI integration, leading to improved outcomes and efficiencies.\n\n### AI Applications in Medicine\n\n1. **Multimodal AI in Healthcare**:\n - AI is being used to assimilate information from diverse sources such as medical images, textual clinical reports, and voice data. This multimodal approach is driving new understandings about health and healthcare, leading to more accurate diagnoses and personalized treatment plans.\n\n2. **Improving Health Outcomes**:\n - AI technologies are transforming care delivery by improving health outcomes, patient safety, and the affordability and accessibility of high-quality care. AI is being used to predict patient outcomes, optimize treatment plans, and monitor patient health in real-time.\n\n3. **Complementary Tool in Healthcare**:\n - AI is increasingly seen as a complementary tool rather than a replacement in healthcare. It assists healthcare professionals in making more informed decisions, thereby enhancing the quality of care provided to patients.\n\n4. **Responsible Data Usage**:\n - The responsible usage of patient data is crucial in AI applications in medicine. Ensuring data privacy and security while leveraging AI for healthcare advancements is a key focus area.\n\n### Conclusion\n\nThe advancements in AI in 2024 are marked by significant trends, breakthrough technologies, and transformative industry impacts. Generative AI, multimodal AI, and model optimization are key trends driving the field forward. Breakthrough technologies like advanced generative models and Claude by Anthropic are setting new benchmarks. The industry impacts are profound, with economic transformation, job market evolution, and sector-specific applications leading the way. In healthcare, AI is revolutionizing care delivery, improving health outcomes, and enhancing patient safety. As AI continues to evolve, it is crucial for stakeholders to stay informed and adapt to these changes to harness the full potential of this revolutionary technology."
2 changes: 2 additions & 0 deletions tests/run_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"blog_with_images_ipynb": "examples/Blog with Images.ipynb",
"multi_step_research_agent_ipynb": "examples/Multi-step research agent.ipynb",
"math_via_python_code_with_a_single_agent_ipynb": "examples/Math via python code with a single agent.ipynb",
"validating_agent_output_ipynb": "examples/Validating agent output.ipynb",
"advanced_output_handling_ipynb": "examples/Advanced output handling.ipynb",
# "using_autogen_with_motleycrew_ipynb": "examples/Using AutoGen with motleycrew.ipynb"
}

Expand Down
Loading