8000 Loop to same node not working · Issue #67 · deepset-ai/canals · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
Loop to same node not working #67
Closed
@MichelBartels

Description

@MichelBartels

When trying to create an agent, I need to store some state in a node. As far as I can tell, the nodes are supposed to be stateless so one alternative is to loop the state back as an input into itself. However, this doesn't work with the current version of canals.

To demonstrate this, I have create the following (slightly non-sensical) example:

from canals import component, Pipeline

@component
class A:
    @component.output_types(goal=int, current=int, final_result=int)
    def run(self, initial_goal: int, goal: int, current: int):
        if initial_goal:
            goal = initial_goal - 1 # For some reason that's a better goal
        if goal == current:
            return {"goal": None, "current": None, "final_result": current}
        return {"goal": goal, "current": current, "final_result": None}

@component
class B:
    @component.output_types(y=int)
    def run(self, x: int):
        return {"y": x + 1}

p = Pipeline()
p.add_component("a", A())
p.add_component("b", B())
p.connect("a.current", "b.x")
p.connect("b.y", "a.current")
p.connect("a.goal", "a.goal")

print(p.run({"a": {"initial_goal": 5, "current": 0}}))

B describes a node that is repeatedly called to perform some action (in this case increase a value by 1). A checks this value and sends it back to B until it satisfies a condition (in this case it should be 4). A should be representative of an agent and the goal field is its state (in a proper agent this would also change over time. It crashes with the following error:

Traceback (most recent call last):
  File "<...>/bug.py", line 26, in <module>
    print(p.run({"a": {"initial_goal": 5, "current": 0}}))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<...>/canals/canals/pipeline/pipeline.py", line 365, in run
    raise PipelineRuntimeError(
canals.errors.PipelineRuntimeError: 'a' is stuck waiting for input, but there are no other components to run. This is likely a Canals bug. Open an issue at https://github.com/deepset-ai/canals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0