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: expose graph name in GraphInfo #17

Merged
merged 1 commit into from
Dec 23, 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
1 change: 1 addition & 0 deletions compose/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ func (g *graph) toGraphInfo(opt *graphCompileOptions, key2SubGraphs map[string]*
}),
InputType: g.expectedInputType,
OutputType: g.expectedOutputType,
Name: opt.graphName,
}

for key := range g.nodes {
Expand Down
8 changes: 5 additions & 3 deletions compose/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func TestGraphCompileCallback(t *testing.T) {
t.Run("graph compile callback", func(t *testing.T) {
type s struct{}

g := NewStateGraph[map[string]any, map[string]any, *s](func(ctx context.Context) *s { return &s{} })
g := NewGraph[map[string]any, map[string]any](WithGenLocalState(func(ctx context.Context) *s { return &s{} }))

lambda := InvokableLambda(func(ctx context.Context, input string) (output string, err error) {
return "node1", nil
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func TestGraphCompileCallback(t *testing.T) {
err = subGraph.AddEdge("sub_sub_1", END)
assert.NoError(t, err)

subGraphCompileOpts := []GraphCompileOption{WithMaxRunSteps(2)}
subGraphCompileOpts := []GraphCompileOption{WithMaxRunSteps(2), WithGraphName("sub_graph")}
subGraphOpts := []GraphAddNodeOpt{WithGraphCompileOptions(subGraphCompileOpts...)}
err = g.AddGraphNode("sub_graph", subGraph, subGraphOpts...)
assert.NoError(t, err)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ func TestGraphCompileCallback(t *testing.T) {
assert.NoError(t, err)

c := &cb{}
opt := []GraphCompileOption{WithGraphCompileCallbacks(c)}
opt := []GraphCompileOption{WithGraphCompileCallbacks(c), WithGraphName("top_level")}
_, err = g.Compile(context.Background(), opt...)
assert.NoError(t, err)
expected := &GraphInfo{
Expand Down Expand Up @@ -1192,6 +1192,7 @@ func TestGraphCompileCallback(t *testing.T) {
Branches: map[string][]GraphBranch{},
InputType: reflect.TypeOf(""),
OutputType: reflect.TypeOf(""),
Name: "sub_graph",
},
},
"node3": {
Expand Down Expand Up @@ -1226,6 +1227,7 @@ func TestGraphCompileCallback(t *testing.T) {
},
InputType: reflect.TypeOf(map[string]any{}),
OutputType: reflect.TypeOf(map[string]any{}),
Name: "top_level",
}

stateFn := c.gInfo.GenStateFn
Expand Down
1 change: 1 addition & 0 deletions compose/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type GraphInfo struct {
Edges map[string][]string // edge start node key -> edge end node key
Branches map[string][]GraphBranch // branch start node key -> branch
InputType, OutputType reflect.Type
Name string

GenStateFn func(context.Context) any
}
Expand Down
Loading