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

confuse about AppendPassthrough #16

Open
musereborn opened this issue Jan 25, 2025 · 1 comment
Open

confuse about AppendPassthrough #16

musereborn opened this issue Jan 25, 2025 · 1 comment

Comments

@musereborn
Copy link

musereborn commented Jan 25, 2025

// =========== build chain ===========
chain := compose.NewChain[map[string]any, string]()
chain.
	AppendLambda(compose.InvokableLambda(func(ctx context.Context, kvs map[string]any) (map[string]any, error) {
		// do some logic to prepare kv as input val for next node
		// just pass through
		logs.Infof("in view lambda: %v", kvs)
		return kvs, nil
	})).
	AppendBranch(compose.NewChainBranch(branchCond).AddLambda("b1", b1).AddLambda("b2", b2)). // nolint: byted_use_receiver_without_nilcheck
	AppendPassthrough().
	AppendParallel(parallel).
	AppendGraph(rolePlayerChain).
	AppendLambda(compose.InvokableLambda(func(ctx context.Context, m *schema.Message) (string, error) {
		// do some logic to check the output or something
		logs.Infof("in view of messages: %v", m.Content)
		return m.Content, nil
	}))

Why is AppendPassthrough() needed at this point? Because I think the branch selects one node's output, and Parallel is also a single node overall, and the outputs of b1/b2 are consistent with the input of Parallel, why is AppendPassthrough still needed? Why can't it be connected directly? When is AppendPassthrough() necessary?

@BytePender
Copy link
Contributor

AppendPassthrough() is currently meaningful.

The reason is that Chain is a simplified wrapper of Graph. When encapsulating Graph's multiple node into a parallel node into AppendParallel, to avoid complexity, it temporarily supports only one predecessor node.

In the future, support for multiple predecessor nodes can be added as needed.

Since the BranchNode has multiple branch nodes, a PassthroughNode is added after the BranchNode to bypass the limitation of the ParallelNode on the number of predecessor nodes.

Thank you for pointing out the issue, and we would also love to hear your thoughts and suggestions~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants