Skip to content

Commit

Permalink
feat: expose graph name in GraphInfo (#17)
Browse files Browse the repository at this point in the history
Change-Id: I945424ec5fdbd0307330aa0bf0b746f71f11a3b8
  • Loading branch information
shentongmartin authored and meguminnnnnnnnn committed Dec 26, 2024
1 parent 82f4718 commit bf9fe3d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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

0 comments on commit bf9fe3d

Please sign in to comment.