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

Directed Acyclic Graph support? #342

Open
joekendal opened this issue Jun 24, 2024 · 3 comments
Open

Directed Acyclic Graph support? #342

joekendal opened this issue Jun 24, 2024 · 3 comments
Assignees
Labels
Question Further information is needed

Comments

@joekendal
Copy link

Question

Apologies if this has been asked in the community somewhere. I'm currently using LangChain with LangGraph but Mirascope looks like a simpler/better alternative to LangChain - is that correct?

and if so, how do you approach LangGraph primitives to have more control over agentic workflows?

@joekendal joekendal added the Question Further information is needed label Jun 24, 2024
@willbakst
Copy link
Contributor

LangGraph reminds me of TensorFlow v1.

Our current focus is to make the primitives for working with LLMs as good as they can be so that writing even more complex agent workflows doesn't require giving up control like using LangGraph seems to require (for example, where are the tools being called? how are they being called? what if I want to do something more custom?).

If we do decide to implement an additional level of abstraction on top of these primitives for building agentic workflows, I would strive to implement a system more like PyTorch 2.0 and less like TensorFlow v1. If there's a graph, it should be run eagerly and not compiled. Creating it should be the same as chaining functions together -- not manually constructing the graph yourself.

There is a reason that PyTorch is currently the clear winner

@joekendal
Copy link
Author

joekendal commented Jun 24, 2024

LangGraph would be great but they require too much boilerplate code to do it. I don't think their concept is wrong, just their implementation is verbose/ugly. Just like LangChain is a good concept but a bad implementation.

I've stumbled on a comment in the slack channel that mentions creating a DAG with the cached_property decorator, but it is less clear how this can achieve the same thing as LangGraph. Perhaps some examples for how to implement these (multi-agent systems) would help with understanding: https://langchain-ai.github.io/langgraph/tutorials/

@willbakst
Copy link
Contributor

I agree with you.

In the new v1 interface you can use computed fields to create chains/graphs easily. For example:

from mirascope.core import openai

@openai.call("gpt-4o")
def recommend_author(genre: str):
    """Recommend an author who writes {genre} book."""

def format_book(title: str, author: str):
    return f"{title} by {author}"

@openai.call("gpt-4o", tools=[format_book])
def recommend_book(genre: str):
    """Recommend a {genre} book written by {author}."""
    return {"computed_fields": {"author": recommend_author(genre)}}

response = recommend_book("fantasy")
if tools := response.tools:
    for tool in tools:
        output = tool.call()
        print(output)
else:
    print(response.content)

You can see here that writing arbitrarily complex chains/DAGs is as simple as just writing functions and calling them. For example, you could wrap the tool-use part of the script in another function and use that as a computed field in another call. The DAG is implicit in how you're calling the functions. The main thing is that you're fully in control.

I think re-implementing the examples you shared using Mirascope would be a great thing to include in the cookbook we're working on, so thank you for sharing! We'll push to have those examples ready for the release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is needed
Projects
None yet
Development

No branches or pull requests

3 participants