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

feat: Agentic chains #117

Closed
1 task done
cvauclair opened this issue Nov 19, 2024 · 1 comment · Fixed by #131
Closed
1 task done

feat: Agentic chains #117

cvauclair opened this issue Nov 19, 2024 · 1 comment · Fixed by #131
Assignees
Milestone

Comments

@cvauclair
Copy link
Contributor

  • I have looked for existing issues (including closed) about this

Feature Request

Add a new high level building block to Rig: the agent chain!

Motivation

Agentic chains (or agent chains, agent pipelines, etc.) have become a cornerstone of building LLM powered applications. Chains are flexible constructs that can be used to chain together multiple agents in a multistep process, define some agentic control flow based or simply to add data processing steps before and after prompting.

Whereas Rig Agents can be considered highly configurable blackboxes, chains make the prompting process explicit and declarative. They would therefore make a great addition to the library.

Proposal

Chains should provide a declarative interface for developers to define some arbitrary flow of operations. In fact, at their most general, chains are simply data processing pipelines where some steps happen to involve AI elements. As such, Rig chains should be implement as general processing pipeline, with some additional quality-of-life helpers for common LLM-related operations (e.g.: prompting a model/agent, RAGging documents, etc.). See the code snippet below for a proof of concept.

Chains would be analogous to Rust Iterators (or Streams) with two key differences:

  1. They do not hold values (in other words, whereas Iterators have an associated type Item, chains would have two associated types Input and Output)
  2. They operate on a single value at a time
// Proof of concept
let chain = chain::new()
    // Retrieve top document from the index and return it with the prompt
    .lookup(index, 2)

    // Format the prompt with the context documents if the previous step 
    // was successful
    .map_ok(|(query, docs): (_, Vec<String>)| {
        format!(
            "User question: {}\n\nWord definitions:\n{}",
            query,
            docs.join("\n")
        )
    })
    
    // Prompt the agent
    .prompt(&agent);

let response = chain.call("What does \"glarb-glarb\" mean?").await?;

Alternatives

Alternatives explored included leveraging existing Rust Iterators and/or Streams to implement Rig chains, but these proved to be inadequate.

@cvauclair cvauclair self-assigned this Nov 19, 2024
@cvauclair cvauclair linked a pull request Nov 29, 2024 that will close this issue
@awdemos
Copy link

awdemos commented Dec 4, 2024

  1. I super like your implementation in Rust and I learned a lot from reading it.

  2. I have to comment on this Langchain sourced marketing nonsense:

"Agentic chains (or agent chains, agent pipelines, etc.) have become a cornerstone of building LLM powered applications."

No not really. A cornerstone has a specific meaning in construction and masonry and certain concepts in computing have parallels. It would be correct to say that TCP/IP is a cornerstone of computer networking. While Agentic chains are a useful data structure to describe it as "the cornerstone of agentic systems" is a marketing statement and not an engineering one.

"Chains are flexible constructs that can be used to chain together multiple agents in a multistep process, define some agentic control flow based or simply to add data processing steps before and after prompting."

Sure and that's fine but that is not what most people who deploy agents want and in exchange for this feature it introduces computational cost and latency, and introduces complexity that is difficult for human programmers to keep track of. How do you manage to scale chains? At what point is adding more "chains" a waste of time and money? I know that's a job for the programmer to figure out but it's something to be mindful about when introducing complexity for the sake of introducing complexity when most people don't need this.

Whereas Rig Agents can be considered highly configurable blackboxes, chains make the prompting process explicit and declarative. They would therefore make a great addition to the library.

They can also be considered not as blackboxes but as carefully designed lightweight interfaces, making your point moot. I'm not entirely sure what you mean by "chains make the prompting process explicit and declarative." Prompting is already inherent and explicit and declarative in LLMs. Try making an LLM without a prompt and get back to us on how it goes. I am not sure how writing multiple prompts for multiple agents makes the process more explicit and declarative in the way that writing declarative infrastructure as code is. I'm open to becoming better informed on this if there is something I am explicitly missing. Chains as a data structure make the prompting process for inputs and outputs across multiple agents explicit but is not strictly necessary or desirable in a lot of use cases. Engineering cool things is fine misleading statements in order to make a case for it is tired.

@mateobelanger mateobelanger added this to the v0.6 milestone Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants