Skip to content
Open
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 adk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This directory provides examples for Eino ADK:
- `middlewares`
- `skill`: loads Agent skills from filesystem.
- `dynamictool/toolsearch`: dynamically retrieves and injects relevant tools from a large tool set.
- `team`: how to create agent teams from scratch.
- `common`
- `tool/graphtool`: wraps Graph/Chain/Workflow as Agent tools.
- `model`, `prints`, `store`, `trace`: shared helpers used by examples.
Expand Down
10 changes: 5 additions & 5 deletions adk/intro/http-sse-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.24.9
replace github.com/cloudwego/eino-examples => ../../..

require (
github.com/cloudwego/eino v0.9.0-beta.1
github.com/cloudwego/eino v0.9.9
github.com/cloudwego/eino-examples v0.0.0-00010101000000-000000000000
github.com/cloudwego/hertz v0.10.3
github.com/hertz-contrib/sse v0.1.0
Expand All @@ -19,9 +19,9 @@ require (
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/cloudwego/eino-ext/components/model/ark v0.1.65 // indirect
github.com/cloudwego/eino-ext/components/model/openai v0.1.12 // indirect
github.com/cloudwego/eino-ext/libs/acl/openai v0.1.16 // indirect
github.com/cloudwego/eino-ext/components/model/ark v0.1.68 // indirect
github.com/cloudwego/eino-ext/components/model/openai v0.1.13 // indirect
github.com/cloudwego/eino-ext/libs/acl/openai v0.1.17 // indirect
github.com/cloudwego/gopkg v0.1.4 // indirect
github.com/cloudwego/netpoll v0.7.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand Down Expand Up @@ -49,7 +49,7 @@ require (
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/volcengine/volc-sdk-golang v1.0.199 // indirect
github.com/volcengine/volcengine-go-sdk v1.2.27 // indirect
github.com/volcengine/volcengine-go-sdk v1.2.28 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
golang.org/x/arch v0.19.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions adk/intro/http-sse-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,16 @@ github.com/cloudwego/eino v0.9.0-alpha.18 h1:xBd6wReRd8a4kcICvtVAaDZywMQ5Yw+ip+x
github.com/cloudwego/eino v0.9.0-alpha.18/go.mod h1:OBD1mrkfkt/pJa4rkg1P0VnaMeOVl7l8IAdEqY//3IQ=
github.com/cloudwego/eino v0.9.0-alpha.22/go.mod h1:OBD1mrkfkt/pJa4rkg1P0VnaMeOVl7l8IAdEqY//3IQ=
github.com/cloudwego/eino v0.9.0-alpha.24/go.mod h1:OBD1mrkfkt/pJa4rkg1P0VnaMeOVl7l8IAdEqY//3IQ=
github.com/cloudwego/eino v0.9.9/go.mod h1:OBD1mrkfkt/pJa4rkg1P0VnaMeOVl7l8IAdEqY//3IQ=
github.com/cloudwego/eino-ext/components/model/ark v0.1.65 h1:52ukXVU9ntToTa36SwI8be81qskGkpUEZraIFOf0wqk=
github.com/cloudwego/eino-ext/components/model/ark v0.1.65/go.mod h1:aabMR15RTXBSi9Eu13CWavzE+no5BQO4FJUEEdqImbg=
github.com/cloudwego/eino-ext/components/model/ark v0.1.68/go.mod h1:IctHLV+EmEhf3o2fBw0N873mLIyNlEAAGcEpUGEQdvk=
github.com/cloudwego/eino-ext/components/model/openai v0.1.12 h1:vcwNXeT7bpaXMNwUhtcHZwMYY8II2jAihuooyivmEZ0=
github.com/cloudwego/eino-ext/components/model/openai v0.1.12/go.mod h1:ve/+/hLZMvxD5AieQ355xHIFhAZVlsG4rdwTnE16aQU=
github.com/cloudwego/eino-ext/components/model/openai v0.1.13/go.mod h1:mgIoqYYOc0eECCqvLbEYpOJrQNTNxkwXzSJzFU+v5sQ=
github.com/cloudwego/eino-ext/libs/acl/openai v0.1.16 h1:q242n5P5Tx3a2QLaBmkfEpfRs/o17Ac6u3EAgItEEOc=
github.com/cloudwego/eino-ext/libs/acl/openai v0.1.16/go.mod h1:p+l0zBB0GjjX8HTlbTs3g3KfUFwZC11bsCGZOXW/3L0=
github.com/cloudwego/eino-ext/libs/acl/openai v0.1.17/go.mod h1:Zkcx6DPTR2NfWmtSXbhItswGw6hqUezNPhNcke0pOG8=
github.com/cloudwego/gopkg v0.1.4 h1:EoQiCG4sTonTPHxOGE0VlQs+sQR+Hsi2uN0qqwu8O50=
github.com/cloudwego/gopkg v0.1.4/go.mod h1:FQuXsRWRsSqJLsMVd5SYzp8/Z1y5gXKnVvRrWUOsCMI=
github.com/cloudwego/hertz v0.10.3 h1:NFcQAjouVJsod79XPLC/PaFfHgjMTYbiErmW+vGBi8A=
Expand Down Expand Up @@ -514,6 +518,7 @@ github.com/volcengine/volc-sdk-golang v1.0.199/go.mod h1:stZX+EPgv1vF4nZwOlEe8iG
github.com/volcengine/volcengine-go-sdk v1.2.9 h1:du2gnImtyWXKkQFnJW/GXCs+UBibGGOXIbP1Ams2pB8=
github.com/volcengine/volcengine-go-sdk v1.2.9/go.mod h1:oxoVo+A17kvkwPkIeIHPVLjSw7EQAm+l/Vau1YGHN+A=
github.com/volcengine/volcengine-go-sdk v1.2.27/go.mod h1:oxoVo+A17kvkwPkIeIHPVLjSw7EQAm+l/Vau1YGHN+A=
github.com/volcengine/volcengine-go-sdk v1.2.28/go.mod h1:oxoVo+A17kvkwPkIeIHPVLjSw7EQAm+l/Vau1YGHN+A=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
Expand Down
174 changes: 174 additions & 0 deletions adk/middlewares/team/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Copyright 2026 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"context"
"fmt"
"os"
"path/filepath"
"sync"
"time"

"github.com/cloudwego/eino/adk/middlewares/filesystem"
"github.com/cloudwego/eino/adk/prebuilt/team"
)

// ---------------------------------------------------------------------------
// File-based Backend that persists data to the filesystem
// ---------------------------------------------------------------------------

type fileBackend struct {
baseDir string
mu sync.RWMutex
seededInboxes map[string]bool
}

func newFileBackend(baseDir string) *fileBackend {
if baseDir == "" {
baseDir = os.TempDir()
}
return &fileBackend{
baseDir: baseDir,
seededInboxes: make(map[string]bool),
}
}

func (b *fileBackend) LsInfo(_ context.Context, req *team.LsInfoRequest) ([]team.FileInfo, error) {
entries, err := os.ReadDir(req.Path)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, fmt.Errorf("read dir %s: %w", req.Path, err)
}

var result []team.FileInfo
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
continue
}
result = append(result, team.FileInfo{
Path: filepath.Join(req.Path, entry.Name()),
IsDir: entry.IsDir(),
Size: info.Size(),
ModifiedAt: info.ModTime().UTC().Format(time.RFC3339),
})
}
return result, nil
}

func (b *fileBackend) Read(_ context.Context, req *team.ReadRequest) (*filesystem.FileContent, error) {
data, err := os.ReadFile(req.FilePath)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("file not found: %s", req.FilePath)
}
return nil, fmt.Errorf("read file %s: %w", req.FilePath, err)
}
return &filesystem.FileContent{Content: string(data)}, nil
}

func (b *fileBackend) Write(_ context.Context, req *team.WriteRequest) error {
dir := filepath.Dir(req.FilePath)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("create dir %s: %w", dir, err)
}

content := req.Content

// Atomic replace: write to a temp file in the same directory, fsync, then
// rename over the target. This satisfies the team.Backend durability contract
// so a crash mid-write can never leave a truncated config.json or inbox.
tmp, err := os.CreateTemp(dir, "."+filepath.Base(req.FilePath)+".tmp-*")
if err != nil {
return fmt.Errorf("create temp file for %s: %w", req.FilePath, err)
}
tmpName := tmp.Name()
// Best-effort cleanup if we bail out before the rename succeeds.
defer func() { _ = os.Remove(tmpName) }()

if _, err := tmp.WriteString(content); err != nil {
_ = tmp.Close()
return fmt.Errorf("write temp file for %s: %w", req.FilePath, err)
}
if err := tmp.Sync(); err != nil {
_ = tmp.Close()
return fmt.Errorf("sync temp file for %s: %w", req.FilePath, err)
}
if err := tmp.Close(); err != nil {
return fmt.Errorf("close temp file for %s: %w", req.FilePath, err)
}
if err := os.Chmod(tmpName, 0644); err != nil {
return fmt.Errorf("chmod temp file for %s: %w", req.FilePath, err)
}
if err := os.Rename(tmpName, req.FilePath); err != nil {
return fmt.Errorf("rename temp file to %s: %w", req.FilePath, err)
}
return nil
}

func (b *fileBackend) Delete(_ context.Context, req *team.DeleteRequest) error {
info, err := os.Stat(req.FilePath)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("stat %s: %w", req.FilePath, err)
}

if info.IsDir() {
if err := os.RemoveAll(req.FilePath); err != nil {
return fmt.Errorf("remove dir %s: %w", req.FilePath, err)
}
} else {
if err := os.Remove(req.FilePath); err != nil {
return fmt.Errorf("remove file %s: %w", req.FilePath, err)
}
}
return nil
}

func (b *fileBackend) Exists(_ context.Context, path string) (bool, error) {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("stat %s: %w", path, err)
}
return true, nil
}

func (b *fileBackend) Mkdir(_ context.Context, path string) error {
if err := os.MkdirAll(path, 0755); err != nil {
return fmt.Errorf("mkdir %s: %w", path, err)
}
return nil
}

func (b *fileBackend) FileExists(_ context.Context, path string) (bool, error) {
info, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("stat %s: %w", path, err)
}
return !info.IsDir(), nil
}
97 changes: 97 additions & 0 deletions adk/middlewares/team/chat_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2026 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"context"
"fmt"
"os"

"github.com/cloudwego/eino-ext/components/model/ark"
"github.com/cloudwego/eino-ext/components/model/openai"
arkmodel "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"

"github.com/cloudwego/eino/components/model"
)

func NewChatModel(ctx context.Context) (cm model.ToolCallingChatModel, err error) {
o := &option{}

if modelName := os.Getenv("ARK_MODEL"); modelName != "" {
conf := &ark.ChatModelConfig{
APIKey: os.Getenv("ARK_API_KEY"),
BaseURL: os.Getenv("ARK_BASE_URL"),
Region: os.Getenv("ARK_REGION"),
Model: modelName,
MaxTokens: o.MaxTokens,
Temperature: o.Temperature,
TopP: o.TopP,
}
if o.DisableThinking != nil && *o.DisableThinking {
conf.Thinking = &arkmodel.Thinking{
Type: arkmodel.ThinkingTypeDisabled,
}
}
if o.JsonSchema != nil {
conf.ResponseFormat = &ark.ResponseFormat{
Type: arkmodel.ResponseFormatJSONSchema,
JSONSchema: &arkmodel.ResponseFormatJSONSchemaJSONSchemaParam{
Name: o.JsonSchema.Name,
Description: o.JsonSchema.Description,
Schema: o.JsonSchema.JSONSchema,
Strict: o.JsonSchema.Strict,
},
}
}
cm, err = ark.NewChatModel(ctx, conf)

} else if modelName = os.Getenv("OPENAI_MODEL"); modelName != "" {
conf := &openai.ChatModelConfig{
APIKey: os.Getenv("OPENAI_API_KEY"),
ByAzure: func() bool {
return os.Getenv("OPENAI_BY_AZURE") == "true"
}(),
BaseURL: os.Getenv("OPENAI_BASE_URL"),
Model: modelName,
MaxTokens: o.MaxTokens,
Temperature: o.Temperature,
}
if o.JsonSchema != nil {
conf.ResponseFormat = &openai.ChatCompletionResponseFormat{
Type: openai.ChatCompletionResponseFormatTypeJSONSchema,
JSONSchema: o.JsonSchema,
}
}
cm, err = openai.NewChatModel(ctx, conf)
}
if err != nil {
return nil, err
}
if cm == nil {
return nil, fmt.Errorf("no model config")
}

return cm, nil
}

type option struct {
MaxTokens *int
Temperature *float32
TopP *float32
DisableThinking *bool
JsonSchema *openai.ChatCompletionResponseFormatJSONSchema
}
Loading
Loading