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
90 changes: 90 additions & 0 deletions adk/prebuilt/deepagents/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package deepagents

const (
defaultAgentName = "DeepAgents"
defaultAgentDescription = "A DeepAgents agent with planning, storage management, sub-agent generation, and long-term memory capabilities"
defaultMaxIterations = 20
defaultInstruction = `You are {agent_name}, an advanced AI agent with planning, execution, memory, and storage capabilities. You excel at breaking down complex tasks, managing information, and systematically achieving goals.

## YOUR CORE CAPABILITIES

### 1. Planning & Task Management
**write_todos**: Break down complex objectives into clear, actionable steps
- Create comprehensive step-by-step plans
- Organize tasks in logical order
- Track progress through task completion

### 2. Storage & File Management
Manage a persistent workspace with full file system capabilities:

**ls**: List files and directories
- Explore directory contents
- Understand workspace structure

**read_file**: Read file contents
- Access existing files
- Review code, documentation, or data

**write_file**: Create or overwrite files
- Generate new files
- Update existing content completely

**edit_file**: Modify files precisely
- Insert new content at specific lines
- Replace sections of existing files
- Delete specific line ranges
- Maintain file integrity while making targeted changes

### 3. Long-term Memory System
Store and retrieve information across sessions:

**remember**: Store important information for future reference
- Save key insights, decisions, or facts
- Tag memories with metadata for easy retrieval
- Build a persistent knowledge base

**recall**: Retrieve previously stored memories
- Access specific memories by key
- Search across all stored information
- Leverage past knowledge for current tasks

**update_memory**: Modify existing memories
- Refine stored information as understanding evolves
- Keep knowledge base current and accurate

**forget**: Remove outdated or irrelevant memories
- Clean up memory store
- Remove sensitive or temporary information

**list_memories**: Browse all stored memories
- Get an overview of available knowledge
- Discover relevant past information

## YOUR APPROACH

1. **Understand**: Carefully analyze the task and break it down
2. **Plan**: Use write_todos to create a clear execution strategy
3. **Execute**: Systematically work through each step
4. **Remember**: Store important learnings and outcomes
5. **Iterate**: Refine your approach based on results

## WORKING MEMORY vs LONG-TERM MEMORY

- **Working Memory (Current Task)**: Your immediate context, todos, and execution state
- Automatically maintained during task execution
- Cleared when task completes

- **Long-term Memory (Persistent Knowledge)**: Information that persists across sessions
- Use remember/recall tools explicitly
- Survives beyond current task
- Helps with future similar tasks

## TASK

{task_description}

{additional_capabilities}

Focus on systematic execution, clear communication, and building useful long-term knowledge.
`
)
145 changes: 145 additions & 0 deletions adk/prebuilt/deepagents/deepagents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright 2025 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 deepagents

import (
"context"
"errors"

"github.com/cloudwego/eino/adk"
"github.com/cloudwego/eino/components/model"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/compose"
)

// Config provides configuration options for creating a DeepAgents agent.
//
// DeepAgents is an ADK-based agent that provides enhanced capabilities for
// planning, storage management, sub-agent generation, and long-term memory.
//
// Memory Architecture:
// - Session: Used internally for current execution context (todos, intermediate results)
// - MemoryStore: Provides long-term persistent memory across sessions (based on CheckPoint)
//
// The agent can be used standalone or integrated into larger workflows (e.g., as a node in compose.StateGraph).
type Config struct {
// Model is the chat model used by the main agent.
// Required.
Model model.ToolCallingChatModel

// Storage is the storage interface implementation for file operations.
// Required. Users should provide an implementation (e.g., from eino-ext).
Storage Storage

// MemoryStore is the memory store for long-term persistence.
// Optional. If provided, enables long-term memory tools (remember, recall, etc.).
// Concrete implementations should be in eino-ext (e.g., CheckPointMemoryStore).
MemoryStore MemoryStore

// ToolsConfig specifies additional tools available to the agent.
// Optional.
ToolsConfig adk.ToolsConfig

// MaxIterations defines the upper limit of ChatModel generation cycles.
// Optional. Defaults to 20.
MaxIterations int

// Instruction is the system prompt for the agent.
// Optional.
Instruction string
}

// New creates a new DeepAgents agent with the given configuration.
//
// DeepAgents provides the following capabilities:
// 1. Planning and task decomposition: write_todos tool
// 2. Storage management: ls, read_file, write_file, edit_file tools
// 3. Sub-agent generation: task tool
// 4. Long-term memory: remember, recall, update_memory, forget, list_memories tools (if MemoryStore provided)
//
// The agent uses Session (adk.Session) for managing current execution context (todos, etc.).
// For long-term persistence across sessions, MemoryStore is used (backed by CheckPoint).
//
// The agent uses the provided Storage interface for all file operations,
// allowing for flexible storage backends (in-memory, file system, S3, etc.).
//
// The returned agent can be used standalone or integrated into a StateGraph as a node.
func New(ctx context.Context, cfg *Config) (adk.Agent, error) {
if cfg == nil {
return nil, errors.New("config is required")
}

if cfg.Model == nil {
return nil, errors.New("model is required")
}

if cfg.Storage == nil {
return nil, errors.New("storage is required")
}

// Build the tools list
tools := make([]tool.BaseTool, 0)

// 1. Add write_todos tool for planning
writeTodosTool := NewWriteTodosTool()
tools = append(tools, writeTodosTool)

// 2. Add storage tools
storageTools := NewStorageTools(cfg.Storage)
tools = append(tools, storageTools...)

// 3. Add memory tools (if MemoryStore is provided)
if cfg.MemoryStore != nil {
memoryTools := NewMemoryTools(cfg.MemoryStore)
tools = append(tools, memoryTools...)
}

// 4. Add task tool for sub-agent creation
taskTool := NewTaskTool(cfg.Model)
tools = append(tools, taskTool)

// 5. Add any additional tools from ToolsConfig
if cfg.ToolsConfig.Tools != nil {
tools = append(tools, cfg.ToolsConfig.Tools...)
}

if cfg.Instruction == "" {
cfg.Instruction = defaultInstruction
}

// Create the main agent
toolsConfig := adk.ToolsConfig{
ToolsNodeConfig: compose.ToolsNodeConfig{
Tools: tools,
},
ReturnDirectly: cfg.ToolsConfig.ReturnDirectly,
}

agent, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
Name: "DeepAgents",
Description: "A DeepAgents agent with planning, storage management, sub-agent generation, and long-term memory capabilities",
Instruction: cfg.Instruction,
Model: cfg.Model,
ToolsConfig: toolsConfig,
MaxIterations: cfg.MaxIterations,
})
if err != nil {
return nil, err
}

return agent, nil
}
Loading