Skip to content
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
56 changes: 56 additions & 0 deletions agent/workflowagents/loopagent/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
//
// 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 loopagent

import (
"github.com/volcengine/veadk-go/common"
"github.com/volcengine/veadk-go/prompts"
"google.golang.org/adk/agent"
googleADKLoopAgent "google.golang.org/adk/agent/workflowagents/loopagent"
)

// Config defines the configuration for a veLoopAgent.
type Config struct {
// Basic agent setup.
AgentConfig agent.Config

// If MaxIterations == 0, then LoopAgent runs indefinitely or until any
// sub-agent escalates.
MaxIterations uint

//TODO: add tracers
}

// New creates a LoopAgent.
//
// LoopAgent repeatedly runs its sub-agents in sequence for a specified number
// of iterations or until a termination condition is met.
//
// Use the LoopAgent when your workflow involves repetition or iterative
// refinement, such as like revising code.
func New(cfg Config) (agent.Agent, error) {

if cfg.AgentConfig.Name == "" {
cfg.AgentConfig.Name = common.DEFAULT_LOOPAGENT_NAME
}
if cfg.AgentConfig.Description == "" {
cfg.AgentConfig.Description = prompts.DEFAULT_DESCRIPTION
}

return googleADKLoopAgent.New(googleADKLoopAgent.Config{
AgentConfig: cfg.AgentConfig,
MaxIterations: cfg.MaxIterations,
})
}
50 changes: 50 additions & 0 deletions agent/workflowagents/sequentialagent/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
//
// 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 sequentialagent

import (
"github.com/volcengine/veadk-go/common"
"github.com/volcengine/veadk-go/prompts"
"google.golang.org/adk/agent"
googleADKSequentialAgent "google.golang.org/adk/agent/workflowagents/sequentialagent"
)

// Config defines the configuration for a SequentialAgent.
type Config struct {
// Basic agent setup.
AgentConfig agent.Config

//TODO: add tracers
}

// New creates a SequentialAgent.
//
// SequentialAgent executes its sub-agents once, in the order they are listed.
//
// Use the SequentialAgent when you want the execution to occur in a fixed,
// strict order.
func New(cfg Config) (agent.Agent, error) {

if cfg.AgentConfig.Name == "" {
cfg.AgentConfig.Name = common.DEFAULT_SEQUENTIALAGENT_NAME
}
if cfg.AgentConfig.Description == "" {
cfg.AgentConfig.Description = prompts.DEFAULT_DESCRIPTION
}

return googleADKSequentialAgent.New(googleADKSequentialAgent.Config{
AgentConfig: cfg.AgentConfig,
})
}
3 changes: 3 additions & 0 deletions common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
)

const DEFAULT_LLMAGENT_NAME = "veAgent"
const DEFAULT_LOOPAGENT_NAME = "veLoopAgent"
const DEFAULT_PARALLELAGENT_NAME = "veParallelAgent"
const DEFAULT_SEQUENTIALAGENT_NAME = "veSequentialAgent"

const VEFAAS_IAM_CRIDENTIAL_PATH = "/var/run/secrets/iam/credential"

Expand Down
121 changes: 121 additions & 0 deletions examples/workflowagents/loopagent/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
//
// 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"
"log"
"os"

veagent "github.com/volcengine/veadk-go/agent/llmagent"
"github.com/volcengine/veadk-go/agent/workflowagents/loopagent"
"google.golang.org/adk/agent"
"google.golang.org/adk/agent/llmagent"
"google.golang.org/adk/cmd/launcher"
"google.golang.org/adk/cmd/launcher/full"
"google.golang.org/adk/session"
"google.golang.org/adk/tool"
"google.golang.org/adk/tool/functiontool"
)

func main() {
ctx := context.Background()

exitLoopTool, err := GetExitLoopTool()
if err != nil {
fmt.Printf("GetExitLoopTool failed: %v", err)
return
}

plannerAgent, err := veagent.New(&veagent.Config{
Config: llmagent.Config{
Name: "planner_agent",
Description: "Decomposes a complex task into smaller actionable steps.",
Instruction: "Given the user's goal and current progress, decide the NEXT step to take. You don't need to execute the step, just describe it clearly. If all steps are done, respond with 'TASK COMPLETE'.",
},
ModelExtraConfig: map[string]any{
"extra_body": map[string]any{
"thinking": map[string]string{
"type": "disabled",
},
},
},
})
if err != nil {
fmt.Printf("NewLLMAgent plannerAgent failed: %v", err)
return
}

executorAgent, err := veagent.New(&veagent.Config{
Config: llmagent.Config{
Name: "executor_agent",
Description: "Executes a given step and returns the result.",
Instruction: "Execute the provided step and describe what was done or what result was obtained. If you received 'TASK COMPLETE', you must call the 'exit_loop' function. Do not output any text.",
Tools: []tool.Tool{exitLoopTool},
},
ModelExtraConfig: map[string]any{
"extra_body": map[string]any{
"thinking": map[string]string{
"type": "disabled",
},
},
},
})
if err != nil {
fmt.Printf("NewLLMAgent executorAgent failed: %v", err)
return
}

rootAgent, err := loopagent.New(loopagent.Config{
AgentConfig: agent.Config{
SubAgents: []agent.Agent{plannerAgent, executorAgent},
Description: "Executes a sequence of code writing, reviewing, and refactoring.",
},
MaxIterations: 3,
})

if err != nil {
fmt.Printf("NewSequentialAgent failed: %v", err)
return
}

config := &launcher.Config{
AgentLoader: agent.NewSingleLoader(rootAgent),
SessionService: session.InMemoryService(),
}

l := full.NewLauncher()
if err = l.Execute(ctx, config, os.Args[1:]); err != nil {
log.Fatalf("Run failed: %v\n\n%s", err, l.CommandLineSyntax())
}
}

type ExitLoopToolArgs struct {
Name string `json:"name" jsonschema:"name of the agent invoke exit loop tool"`
}

func GetExitLoopTool() (tool.Tool, error) {
handler := func(ctx tool.Context, args ExitLoopToolArgs) (map[string]any, error) {
ctx.Actions().Escalate = true
return map[string]any{}, nil
}
return functiontool.New(
functiontool.Config{
Name: "exit_loop",
Description: `A tools to exit the loop`,
},
handler)
}
95 changes: 95 additions & 0 deletions examples/workflowagents/sequentialagent/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
//
// 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"
"log"
"os"

veagent "github.com/volcengine/veadk-go/agent/llmagent"
"github.com/volcengine/veadk-go/agent/workflowagents/sequentialagent"
"google.golang.org/adk/agent"
"google.golang.org/adk/agent/llmagent"
"google.golang.org/adk/cmd/launcher"
"google.golang.org/adk/cmd/launcher/full"
"google.golang.org/adk/session"
)

func main() {
ctx := context.Background()

greetingAgent, err := veagent.New(&veagent.Config{
Config: llmagent.Config{
Name: "greeting_agent",
Description: "A friendly agent that greets the user.",
Instruction: "Greet the user warmly.",
},
ModelExtraConfig: map[string]any{
"extra_body": map[string]any{
"thinking": map[string]string{
"type": "disabled",
},
},
},
})
if err != nil {
fmt.Printf("NewLLMAgent greetingAgent failed: %v", err)
return
}

goodbyeAgent, err := veagent.New(&veagent.Config{
Config: llmagent.Config{
Name: "goodbye_agent",
Description: "A polite agent that says goodbye to the user.",
Instruction: "Directly return goodbye",
},
ModelExtraConfig: map[string]any{
"extra_body": map[string]any{
"thinking": map[string]string{
"type": "disabled",
},
},
},
})
if err != nil {
fmt.Printf("NewLLMAgent goodbyeAgent failed: %v", err)
return
}

rootAgent, err := sequentialagent.New(sequentialagent.Config{
AgentConfig: agent.Config{
Name: "veAgent",
SubAgents: []agent.Agent{greetingAgent, goodbyeAgent},
Description: "Executes a sequence of greeting and goodbye.",
},
})

if err != nil {
fmt.Printf("NewSequentialAgent failed: %v", err)
return
}

config := &launcher.Config{
AgentLoader: agent.NewSingleLoader(rootAgent),
SessionService: session.InMemoryService(),
}

l := full.NewLauncher()
if err = l.Execute(ctx, config, os.Args[1:]); err != nil {
log.Fatalf("Run failed: %v\n\n%s", err, l.CommandLineSyntax())
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/volcengine/volc-sdk-golang v1.0.229
github.com/volcengine/volcengine-go-sdk v1.1.53
go.uber.org/zap v1.27.1
google.golang.org/adk v0.2.0
google.golang.org/genai v1.36.0
google.golang.org/adk v0.3.0
google.golang.org/genai v1.40.0
gopkg.in/go-playground/validator.v8 v8.18.2
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/postgres v1.6.0
Expand All @@ -24,7 +24,7 @@ require (
cloud.google.com/go v0.123.0 // indirect
cloud.google.com/go/auth v0.17.0 // indirect
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/a2aproject/a2a-go v0.3.0 // indirect
github.com/a2aproject/a2a-go v0.3.3 // indirect
github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect
github.com/bytedance/sonic v1.14.2 // indirect
github.com/bytedance/sonic/loader v0.4.0 // indirect
Expand Down
Loading