### Install Eino Components Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-component/SKILL.md Use 'go get' to install specific Eino component implementations. Examples show installation for models, retrievers, and tools. ```bash go get github.com/cloudwego/eino-ext/components/{type}/{impl}@latest # Examples: go get github.com/cloudwego/eino-ext/components/model/openai@latest go get github.com/cloudwego/eino-ext/components/model/agenticopenai@latest go get github.com/cloudwego/eino-ext/components/retriever/milvus2@latest go get github.com/cloudwego/eino-ext/components/tool/mcp@latest ``` -------------------------------- ### Install CommandLine Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/commandline/README.md Install the commandline tool using go get. ```bash go get github.com/cloudwego/eino-ext/components/tool/commandline@latest ``` -------------------------------- ### Full Example with Options Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-component/reference/callback/cozeloop.md A complete example demonstrating the setup of the CozeLoop handler with tracing enabled, followed by an example Eino component call that will be traced. ```APIDOC ## Full Example ```go import ( ccb "github.com/cloudwego/eino-ext/callbacks/cozeloop" "github.com/cloudwego/eino/callbacks" "github.com/coze-dev/cozeloop-go" "github.com/cloudwego/eino/components/openai" "github.com/cloudwego/eino/schema" "context" "log" ) func main() { ctx := context.Background() client, err := cozeloop.NewClient() if err != nil { log.Fatal(err) } defer client.Close(ctx) handler := ccb.NewLoopHandler(client, ccb.WithEnableTracing(true), ) callbacks.AppendGlobalHandlers(handler) // All Eino component calls are now traced chatModel, _ := openai.NewChatModel(ctx, &openai.ChatModelConfig{ Model: "gpt-4o", }) resp, _ := chatModel.Generate(ctx, []*schema.Message{ {Role: schema.User, Content: "Hello"}, }) } ``` ``` -------------------------------- ### Install Qdrant Retriever Source: https://github.com/cloudwego/eino-ext/blob/main/components/retriever/qdrant/README.md Install the Qdrant retriever component using go get. ```bash go get github.com/cloudwego/eino-ext/components/retriever/qdrant@latest ``` -------------------------------- ### Install Local Backend Source: https://github.com/cloudwego/eino-ext/blob/main/adk/backend/local/README.md Install the local backend package using go get. ```bash go get github.com/cloudwego/eino-ext/adk/backend/local ``` -------------------------------- ### Install MCP Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/mcp/README.md Use 'go get' to install the MCP Tool for Eino. ```bash go get github.com/cloudwego/eino-ext/components/tool/mcp@latest ``` -------------------------------- ### Install Semantic Splitter Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/transformer/splitter/semantic/README_zh.md Use 'go get' to install the semantic splitter component. ```bash go get github.com/cloudwego/eino-ext/components/document/transformer/splitter/semantic ``` -------------------------------- ### Install CozeLoop Callback Source: https://github.com/cloudwego/eino-ext/blob/main/callbacks/cozeloop/README.md Install the CozeLoop callback package using go get. ```bash go get github.com/cloudwego/eino-ext/callbacks/cozeloop ``` -------------------------------- ### Install Sequential Thinking Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/sequentialthinking/README.md Install the Sequential Thinking tool using go get. ```bash go get github.com/cloudwego/eino-ext/components/tool/sequentialthinking@latest ``` -------------------------------- ### Install HTTP Request Tools Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/httprequest/README.md Use 'go get' to install the package. Adjust the module path to match your project structure. ```bash go get github.com/cloudwego/eino-ext/components/tool/httprequest ``` -------------------------------- ### Install Google Search Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/googlesearch/README.md Install the Google Search tool package using go get. ```bash go get github.com/cloudwego/eino-ext/components/tool/googlesearch ``` -------------------------------- ### Install HTML Header Splitter Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/transformer/splitter/html/README.md Install the HTML header splitter component using go get. ```bash go get github.com/cloudwego/eino-ext/components/document/transformer/splitter/html ``` -------------------------------- ### Install Markdown Header Splitter Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/transformer/splitter/markdown/README.md Install the Markdown Header Splitter component using go get. ```bash go get github.com/cloudwego/eino-ext/components/document/transformer/splitter/markdown ``` -------------------------------- ### Quick Start: Using the Official MCP Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/mcp/officialmcp/README.md Demonstrates how to set up an MCP server, create an MCP client, fetch tools, and invoke a tool. Ensure the MCP server is running before attempting to connect. ```go package main import ( "context" "fmt" "log" "net/http" "net/http/httptest" "time" "github.com/cloudwego/eino/components/tool" "github.com/modelcontextprotocol/go-sdk/mcp" omcp "github.com/cloudwego/eino-ext/components/tool/mcp/officialmcp" ) type AddParams struct { X int `json:"x"` Y int `json:"y"` } func Add(ctx context.Context, req *mcp.CallToolRequest, args AddParams) (*mcp.CallToolResult, any, error) { return &mcp.CallToolResult{ Content: []mcp.Content{ &mcp.TextContent{Text: fmt.Sprintf("%d", args.X+args.Y)}, }, }, nil, nil } func main() { httpServer := startMCPServer() time.Sleep(1 * time.Second) ctx := context.Background() cli := getMCPClient(ctx, httpServer.URL) defer cli.Close() mcpTools, err := omcp.GetTools(ctx, &omcp.Config{Cli: cli}) if err != nil { log.Fatal(err) } for i, mcpTool := range mcpTools { fmt.Println(i, ":") info, err := mcpTool.Info(ctx) if err != nil { log.Fatal(err) } fmt.Println("Name:", info.Name) fmt.Println("Desc:", info.Desc) result, err := mcpTool.(tool.InvokableTool).InvokableRun(ctx, `{\"x\":1, \"y\":1}`) if err != nil { log.Fatal(err) } fmt.Println("Result:", result) fmt.Println() } } func getMCPClient(ctx context.Context, addr string) *mcp.ClientSession { transport := &mcp.SSEClientTransport{Endpoint: addr} client := mcp.NewClient(&mcp.Implementation{Name: "test", Version: "v1.0.0"}, nil) sess, err := client.Connect(ctx, transport, nil) if err != nil { log.Fatal(err) } return sess } func startMCPServer() *httptest.Server { server := mcp.NewServer(&mcp.Implementation{Name: "adder", Version: "v0.0.1"}, nil) mcp.AddTool(server, &mcp.Tool{Name: "add", Description: "add two numbers"}, Add) handler := mcp.NewSSEHandler(func(*http.Request) *mcp.Server { return server }, nil) httpServer := httptest.NewServer(handler) return httpServer } ``` -------------------------------- ### Install BrowserUse Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/browseruse/README.md Install the BrowserUse Tool using go get. This command fetches the latest version of the package. ```bash go get github.com/cloudwego/eino-ext/components/tool/browseruse@latest ``` -------------------------------- ### Install agenticopenai Package Source: https://github.com/cloudwego/eino-ext/blob/main/components/model/agenticopenai/README.md Install the agenticopenai package using go get. ```bash go get github.com/cloudwego/eino-ext/components/model/agenticopenai@latest ``` -------------------------------- ### Quick Start: Using MCP Tool with Eino Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/mcp/README.md Demonstrates how to set up an MCP server, retrieve MCP tools, and interact with them using the Eino framework. Ensure the MCP server is running before executing this client code. ```go package main import ( "context" "fmt" "log" "time" "github.com/cloudwego/eino/components/tool" "github.com/mark3labs/mcp-go/client" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" mcpp "github.com/cloudwego/eino-ext/components/tool/mcp" ) func main() { startMCPServer() time.Sleep(1 * time.Second) ctx := context.Background() mcpTools := getMCPTool(ctx) for i, mcpTool := range mcpTools { fmt.Println(i, ":") info, err := mcpTool.Info(ctx) if err != nil { log.Fatal(err) } fmt.Println("Name:", info.Name) fmt.Println("Desc:", info.Desc) fmt.Println() } } func getMCPTool(ctx context.Context) []tool.BaseTool { cli, err := client.NewSSEMCPClient("http://localhost:12345/sse") if err != nil { log.Fatal(err) } err = cli.Start(ctx) if err != nil { log.Fatal(err) } initRequest := mcp.InitializeRequest{} initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION initRequest.Params.ClientInfo = mcp.Implementation{ Name: "example-client", Version: "1.0.0", } _, err = cli.Initialize(ctx, initRequest) if err != nil { log.Fatal(err) } tools, err := mcpp.GetTools(ctx, &mcpp.Config{Cli: cli}) if err != nil { log.Fatal(err) } return tools } func startMCPServer() { svr := server.NewMCPServer("demo", mcp.LATEST_PROTOCOL_VERSION) svr.AddTool(mcp.NewTool("calculate", mcp.WithDescription("Perform basic arithmetic operations"), mcp.WithString("operation", mcp.Required(), mcp.Description("The operation to perform (add, subtract, multiply, divide)"), mcp.Enum("add", "subtract", "multiply", "divide"), ), mcp.WithNumber("x", mcp.Required(), mcp.Description("First number"), ), mcp.WithNumber("y", mcp.Required(), mcp.Description("Second number"), ), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { op := request.Params.Arguments["operation"].(string) x := request.Params.Arguments["x"].(float64) y := request.Params.Arguments["y"].(float64) var result float64 switch op { case "add": result = x + y case "subtract": result = x - y case "multiply": result = x * y case "divide": if y == 0 { return mcp.NewToolResultText("Cannot divide by zero"), nil } result = x / y } log.Printf("Calculated result: %.2f", result) return mcp.NewToolResultText(fmt.Sprintf("%.2f", result)), nil }) go func() { defer func() { e := recover() if e != nil { fmt.Println(e) } }() err := server.NewSSEServer(svr, server.WithBaseURL("http://localhost:12345")).Start("localhost:12345") if err != nil { log.Fatal(err) } }() } ``` -------------------------------- ### Quick Start: Using MCP Prompt with Eino Source: https://github.com/cloudwego/eino-ext/blob/main/components/prompt/mcp/README.md This example demonstrates how to set up an MCP server, obtain an MCP prompt client, and use it to format a prompt with Eino. Ensure the MCP server is running before executing. ```go package main import ( "context" "fmt" "log" "time" "github.com/cloudwego/eino/components/prompt" "github.com/mark3labs/mcp-go/client" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" mcpp "github.com/cloudwego/eino-ext/components/prompt/mcp" ) func main() { startMCPServer() time.Sleep(1 * time.Second) ctx := context.Background() mcpPrompt := getMCPPrompt(ctx) result, err := mcpPrompt.Format(ctx, map[string]interface{}{"persona": "Describe the content of the image"}) if err != nil { log.Fatal(err) } fmt.Println(result) } func getMCPPrompt(ctx context.Context) prompt.ChatTemplate { cli, err := client.NewSSEMCPClient("http://localhost:12345/sse") if err != nil { log.Fatal(err) } err = cli.Start(ctx) if err != nil { log.Fatal(err) } initRequest := mcp.InitializeRequest{} initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION initRequest.Params.ClientInfo = mcp.Implementation{ Name: "example-client", Version: "1.0.0", } _, err = cli.Initialize(ctx, initRequest) if err != nil { log.Fatal(err) } p, err := mcpp.NewPromptTemplate(ctx, &mcpp.Config{Cli: cli, Name: "test"}) if err != nil { log.Fatal(err) } return p } func startMCPServer() { svr := server.NewMCPServer("demo", mcp.LATEST_PROTOCOL_VERSION, server.WithPromptCapabilities(false)) svr.AddPrompt(mcp.Prompt{ Name: "test", }, func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) { return &mcp.GetPromptResult{ Messages: []mcp.PromptMessage{ mcp.NewPromptMessage(mcp.RoleUser, mcp.NewTextContent(request.Params.Arguments["persona"])), mcp.NewPromptMessage(mcp.RoleUser, mcp.NewImageContent("https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg", "image/jpeg")), mcp.NewPromptMessage(mcp.RoleUser, mcp.NewEmbeddedResource(mcp.TextResourceContents{ URI: "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg", MIMEType: "image/jpeg", Text: "resource", })), }, }, nil }) go func() { defer func() { e := recover() if e != nil { fmt.Println(e) } }() err := server.NewSSEServer(svr, server.WithBaseURL("http://localhost:12345")).Start("localhost:12345") if err != nil { log.Fatal(err) } }() } ``` -------------------------------- ### Install agenticgemini Package Source: https://github.com/cloudwego/eino-ext/blob/main/components/model/agenticgemini/README.md Install the agenticgemini package using go get. ```bash go get github.com/cloudwego/eino-ext/components/model/agenticgemini@latest ``` -------------------------------- ### Quick Start: Using BrowserUse Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/browseruse/README.md Demonstrates how to initialize and use the BrowserUse Tool to navigate to a URL. Ensure to handle errors and call Cleanup when done. ```go package main import ( "context" "fmt" "log" "time" "github.com/cloudwego/eino-ext/components/tool/browseruse" ) func main() { ctx := context.Background() but, err := browseruse.NewBrowserUseTool(ctx, &browseruse.Config{}) if err != nil { log.Fatal(err) } url := "https://www.google.com" result, err := but.Execute(&browseruse.Param{ Action: browseruse.ActionGoToURL, URL: &url, }) if err != nil { log.Fatal(err) } fmt.Println(result) time.Sleep(10 * time.Second) but.Cleanup() } ``` -------------------------------- ### Install OpenAI ACL Source: https://github.com/cloudwego/eino-ext/blob/main/libs/acl/openai/README.md Install the OpenAI ACL package using go get. ```bash go get github.com/cloudwego/eino-ext/libs/acl/openai ``` -------------------------------- ### Quick Start: Index Documents with Redis Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/redis/README.md Demonstrates how to initialize the Redis client, embedding component, prepare documents, and index them using the Redis indexer. ```go import ( "context" "fmt" "os" "github.com/cloudwego/eino/schema" "github.com/redis/go-redis/v9" "github.com/cloudwego/eino-ext/components/embedding/ark" "github.com/cloudwego/eino-ext/components/indexer/redis" ) func main() { ctx := context.Background() // 1. Create Redis client client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", DB: 0, }) // 2. Create embedding component emb, _ := ark.NewEmbedder(ctx, &ark.EmbeddingConfig{ APIKey: os.Getenv("ARK_API_KEY"), Region: os.Getenv("ARK_REGION"), Model: os.Getenv("ARK_MODEL"), }) // 3. Prepare documents docs := []*schema.Document{ { ID: "1", Content: "Eiffel Tower: Located in Paris, France.", MetaData: map[string]any{ "location": "France", }, }, { ID: "2", Content: "The Great Wall: Located in China.", MetaData: map[string]any{ "location": "China", }, }, } // 4. Create Redis indexer indexer, _ := redis.NewIndexer(ctx, &redis.IndexerConfig{ Client: client, KeyPrefix: "doc:", BatchSize: 10, Embedding: emb, }) // 5. Index documents ids, err := indexer.Store(ctx, docs) if err != nil { fmt.Printf("index error: %v\n", err) return } fmt.Println("indexed ids:", ids) } ``` -------------------------------- ### Quick Start: Perform a Google Search Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/googlesearch/README.md Demonstrates how to initialize the Google Search tool and perform a search query. Ensure GOOGLE_API_KEY and GOOGLE_SEARCH_ENGINE_ID environment variables are set. ```go package main import ( "context" "encoding/json" "fmt" "log" "os" "github.com/cloudwego/eino-ext/components/tool/googlesearch" ) func main() { ctx := context.Background() googleAPIKey := os.Getenv("GOOGLE_API_KEY") googleSearchEngineID := os.Getenv("GOOGLE_SEARCH_ENGINE_ID") if googleAPIKey == "" || googleSearchEngineID == "" { log.Fatal("GOOGLE_API_KEY and GOOGLE_SEARCH_ENGINE_ID must be set") } searchTool, err := googlesearch.NewTool(ctx, &googlesearch.Config{ APIKey: googleAPIKey, SearchEngineID: googleSearchEngineID, Lang: "en", Num: 10, }) if err != nil { log.Fatal(err) } req := googlesearch.SearchRequest{ Query: "Golang programming", Num: 5, Lang: "en", } args, _ := json.Marshal(req) resp, err := searchTool.InvokableRun(ctx, string(args)) if err != nil { log.Fatal(err) } var searchResp googlesearch.SearchResult json.Unmarshal([]byte(resp), &searchResp) for i, result := range searchResp.Items { fmt.Printf("%d. %s\n %s\n\n", i+1, result.Title, result.Link) } } ``` -------------------------------- ### Install Volcengine Knowledge Retriever Source: https://github.com/cloudwego/eino-ext/blob/main/components/retriever/volc_knowledge/README.md Use 'go get' to install the retriever component. ```bash go get github.com/cloudwego/eino-ext/components/retriever/volc_knowledge ``` -------------------------------- ### Full APMPlus Integration Example Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-component/reference/callback/apmplus.md A complete example demonstrating APMPlus setup, session configuration, and Eino component calls, all of which will be traced. ```go func main() { ctx := context.Background() cbh, shutdown, err := apmplus.NewApmplusHandler(&apmplus.Config{ Host: "apmplus-cn-beijing.volces.com:4317", AppKey: "appkey-xxx", ServiceName: "eino-app", Release: "v1.0.0", }) if err != nil { log.Fatal(err) } defer shutdown(ctx) callbacks.AppendGlobalHandlers(cbh) // Set session for request grouping ctx = apmplus.SetSession(ctx, apmplus.WithSessionID("session_001"), apmplus.WithUserID("user_001"), ) // All Eino component calls are now traced with APMPlus chatModel, _ := openai.NewChatModel(ctx, &openai.ChatModelConfig{ Model: "gpt-4o", }) resp, _ := chatModel.Generate(ctx, []*schema.Message{ {Role: schema.User, Content: "Hello"}, }) } ``` -------------------------------- ### Install Redis Retriever Source: https://github.com/cloudwego/eino-ext/blob/main/components/retriever/redis/README.md Use 'go get' to install the Redis retriever component. ```bash go get github.com/cloudwego/eino-ext/components/retriever/redis@latest ``` -------------------------------- ### Quick Start: Initialize and Store Documents Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/qdrant/README.md Demonstrates how to initialize the Qdrant client and indexer, then store a document. Ensure your embedding component is correctly provided. ```go import ( "context" "github.com/cloudwego/eino/schema" qdrant "github.com/qdrant/go-client/qdrant" "github.com/cloudwego/eino-ext/components/indexer/qdrant" ) func main() { ctx := context.Background() // Create Qdrant client client, _ := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6333, }) // Create indexer indexer, _ := qdrant.NewIndexer(ctx, &qdrant.Config{ Client: client, Collection: "my_collection", VectorDim: 384, Distance: qdrant.Distance_Cosine, Embedding: yourEmbedding, // Your embedding component }) // Store documents docs := []*schema.Document{ {ID: "1", Content: "Hello world", MetaData: map[string]interface{}{"type": "text"}}, } ids, _ := indexer.Store(ctx, docs) } ``` -------------------------------- ### Install Agentic Qwen Model Source: https://github.com/cloudwego/eino-ext/blob/main/components/model/agenticqwen/README.md Install the agenticqwen package using go get. ```bash go get github.com/cloudwego/eino-ext/components/model/agenticqwen@latest ``` -------------------------------- ### Install ES7 Retriever Source: https://github.com/cloudwego/eino-ext/blob/main/components/retriever/es7/README.md Install the ES7 retriever component using go get. ```bash go get github.com/cloudwego/eino-ext/components/retriever/es7@latest ``` -------------------------------- ### Quick Start: StrReplaceEditor Example Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/commandline/README.md Demonstrates creating a file, writing content to it, and viewing its content using the StrReplaceEditor with a Docker sandbox. ```go package main import ( "context" "log" "github.com/cloudwego/eino-ext/components/tool/commandline" "github.com/cloudwego/eino-ext/components/tool/commandline/sandbox" ) func main() { ctx := context.Background() op, err := sandbox.NewDockerSandbox(ctx, &sandbox.Config{}) if err != nil { log.Fatal(err) } // you should ensure that docker has been started before create a docker container err = op.Create(ctx) if err != nil { log.Fatal(err) } defer op.Cleanup(ctx) sre, err := commandline.NewStrReplaceEditor(ctx, &commandline.Config{Operator: op}) if err != nil { log.Fatal(err) } info, err := sre.Info(ctx) if err != nil { log.Fatal(err) } log.Printf("tool name: %s, tool desc: %s", info.Name, info.Desc) content := "hello world" log.Println("create file[test.txt]...") result, err := sre.Execute(ctx, &commandline.StrReplaceEditorParams{ Command: commandline.CreateCommand, Path: "./test.txt", FileText: &content, }) if err != nil { log.Fatal(err) } log.Println("create file result: ", result) log.Println("view file[test.txt]...") result, err = sre.Execute(ctx, &commandline.StrReplaceEditorParams{ Command: commandline.ViewCommand, Path: "./test.txt", }) if err != nil { log.Fatal(err) } log.Println("view file result: ", result) } ``` -------------------------------- ### Install Dify Retriever Source: https://github.com/cloudwego/eino-ext/blob/main/components/retriever/dify/README.md Use 'go get' to install the Dify retriever package. ```bash go get github.com/cloudwego/eino-ext/components/retriever/dify ``` -------------------------------- ### Full CozeLoop Integration Example Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-component/reference/callback/cozeloop.md Demonstrates a complete setup of the CozeLoop handler with tracing enabled, followed by an Eino component call that will be automatically traced. ```go func main() { ctx := context.Background() client, err := cozeloop.NewClient() if err != nil { log.Fatal(err) } defer client.Close(ctx) handler := ccb.NewLoopHandler(client, ccb.WithEnableTracing(true), ) callbacks.AppendGlobalHandlers(handler) // All Eino component calls are now traced chatModel, _ := openai.NewChatModel(ctx, &openai.ChatModelConfig{ Model: "gpt-4o", }) resp, _ := chatModel.Generate(ctx, []*schema.Message{ {Role: schema.User, Content: "Hello"}, }) } ``` -------------------------------- ### Quick Start: PyExecutor Example Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/commandline/README.md Demonstrates executing Python code using the PyExecutor with a Docker sandbox. It prints 'hello world' and logs the result. ```go package main import ( "context" "log" "github.com/cloudwego/eino-ext/components/tool/commandline" "github.com/cloudwego/eino-ext/components/tool/commandline/sandbox" ) func main() { ctx := context.Background() op, err := sandbox.NewDockerSandbox(ctx, &sandbox.Config{}) if err != nil { log.Fatal(err) } // you should ensure that docker has been started before create a docker container err = op.Create(ctx) if err != nil { log.Fatal(err) } defer op.Cleanup(ctx) exec, err := commandline.NewPyExecutor(ctx, &commandline.PyExecutorConfig{Operator: op}) // use python3 by default if err != nil { log.Fatal(err) } info, err := exec.Info(ctx) if err != nil { log.Fatal(err) } log.Printf("tool name: %s, tool desc: %s", info.Name, info.Desc) code := "print(\"hello world\")" log.Printf("execute code:\n%s", code) result, err := exec.Execute(ctx, &commandline.Input{Code: code}) if err != nil { log.Fatal(err) } log.Println("result:\n", result) } ``` -------------------------------- ### Install VikingDB Indexer Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/volc_vikingdb/README.md Install the VikingDB indexer component using go get. ```bash go get github.com/cloudwego/eino-ext/components/indexer/volc_vikingdb@latest ``` -------------------------------- ### DeepAgent Quick Start Example Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-agent/reference/deep-agents.md Demonstrates how to initialize and use DeepAgent for a query. It sets up an OpenAI chat model, an in-memory filesystem backend, and a runner to execute the agent's query. ```go import ( "context" "fmt" "log" "github.com/cloudwego/eino-ext/components/model/openai" "github.com/cloudwego/eino/adk" "github.com/cloudwego/eino/adk/filesystem" "github.com/cloudwego/eino/adk/prebuilt/deep" ) func main() { ctx := context.Background() cm, _ := openai.NewChatModel(ctx, &openai.ChatModelConfig{ APIKey: "your-key", Model: "gpt-4o", }) backend := filesystem.NewInMemoryBackend() agent, err := deep.New(ctx, &deep.Config{ ChatModel: cm, Backend: backend, }) if err != nil { log.Fatal(err) } runner := adk.NewRunner(ctx, adk.RunnerConfig{Agent: agent}) iter := runner.Query(ctx, "Analyze the CSV file at /data/sales.csv and create a summary report") for { event, ok := iter.Next() if !ok { break } if event.Err != nil { log.Fatal(event.Err) } if event.Output != nil && event.Output.MessageOutput != nil { msg, _ := event.Output.MessageOutput.GetMessage() fmt.Printf("[%s] %s\n", event.AgentName, msg.Content) } } } ``` -------------------------------- ### Install Redis Indexer Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/redis/README.md Use 'go get' to install the Redis indexer component. ```bash go get github.com/cloudwego/eino-ext/components/indexer/redis@latest ``` -------------------------------- ### Quick Start: Load Local File with File Loader Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/loader/file/README.md Demonstrates how to initialize and use the File Loader to load a local document. Ensure the file path is correct and handle potential errors during initialization and loading. ```go package main import ( "context" "log" "github.com/cloudwego/eino/components/document" "github.com/cloudwego/eino-ext/components/document/loader/file" ) func main() { ctx := context.Background() loader, err := file.NewFileLoader(ctx, &file.FileLoaderConfig{ UseNameAsID: true, }) if err != nil { log.Fatalf("file.NewFileLoader failed, err=%v", err) } filePath := "./document.txt" docs, err := loader.Load(ctx, document.Source{ URI: filePath, }) if err != nil { log.Fatalf("loader.Load failed, err=%v", err) } log.Printf("doc content: %v", docs[0].Content) log.Printf("Extension: %s\n", docs[0].MetaData[file.MetaKeyExtension]) log.Printf("Source: %s\n", docs[0].MetaData[file.MetaKeySource]) } ``` -------------------------------- ### Quick Start: Build and Use SearXNG Search Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/searxng/README.md Demonstrates how to create a SearXNG search tool client with default configurations and integrate it with Eino's ToolsNode. ```go package main import ( "context" "log" "time" "github.com/cloudwego/eino-ext/components/tool/searxng" "github.com/cloudwego/eino/components/tool" ) func main() { // Create search request configuration requestConfig := &searxng.SearchRequestConfig{ TimeRange: searxng.TimeRangeMonth, Language: searxng.LanguageEn, SafeSearch: searxng.SafeSearchModerate, Engines: []searxng.Engine{searxng.EngineGoogle, searxng.EngineBing}, } // Create client config cfg := &searxng.ClientConfig{ BaseUrl: "https://searx.example.com/search", // Your SearXNG instance URL Timeout: 30 * time.Second, Headers: map[string]string{ "User-Agent": "MyApp/1.0", }, MaxRetries: 3, RequestConfig: requestConfig, // Add request config to client config } // Create the search tool searchTool, err := searxng.BuildSearchInvokeTool(cfg) if err != nil { log.Fatalf("BuildSearchInvokeTool failed, err=%v", err) } // Use with Eino's ToolsNode tools := []tool.BaseTool{searchTool} // ... configure and use with ToolsNode } ``` -------------------------------- ### Install ES7 Indexer Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/es7/README.md Install the ES7 indexer component using go get. ```bash go get github.com/cloudwego/eino-ext/components/indexer/es7@latest ``` -------------------------------- ### Initializing FileSystem Middleware Source: https://github.com/cloudwego/eino-ext/blob/main/skills/eino-agent/reference/middleware.md Demonstrates how to create a FileSystem middleware instance, specifying a backend implementation and optionally configuring shell execution capabilities. The `Backend` is required. ```go import "github.com/cloudwego/eino/adk/middlewares/filesystem" mw, err := filesystem.New(ctx, &filesystem.MiddlewareConfig{ Backend: myBackend, // Required: filesystem.Backend implementation Shell: myShell, // Optional: shell execution (mutually exclusive with StreamingShell) StreamingShell: myStreamShell, // Optional: streaming shell }) ``` -------------------------------- ### Install Score-Based Reranker Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/transformer/reranker/score/README.md Use 'go get' to install the score-based reranker component. ```bash go get github.com/cloudwego/eino-ext/components/document/transformer/reranker/score ``` -------------------------------- ### Quick Start ES7 Indexer Example Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/es7/README.md Demonstrates how to set up an Elasticsearch client, define an index specification, create an embedding component, prepare documents, and use the ES7 indexer to store documents. ```go import ( "context" "fmt" "log" "os" "github.com/cloudwego/eino/components/embedding" "github.com/cloudwego/eino/schema" "github.com/elastic/go-elasticsearch/v7" "github.com/cloudwego/eino-ext/components/embedding/ark" "github.com/cloudwego/eino-ext/components/indexer/es7" ) const ( indexName = "eino_example" fieldContent = "content" fieldContentVector = "content_vector" fieldExtraLocation = "location" docExtraLocation = "location" ) func main() { ctx := context.Background() username := os.Getenv("ES_USERNAME") password := os.Getenv("ES_PASSWORD") // 1. Create ES client client, _ := elasticsearch.NewClient(elasticsearch.Config{ Addresses: []string{"http://localhost:9200"}, Username: username, Password: password, }) // 2. Define Index Specification (Optional: automatically creates index if it doesn't exist) indexSpec := &es7.IndexSpec{ Settings: map[string]any{ "number_of_shards": 1, "number_of_replicas": 0, }, Mappings: map[string]any{ "properties": map[string]any{ fieldContentVector: map[string]any{ "type": "dense_vector", "dims": 1536, }, }, }, } // 3. Create embedding component using ARK emb, _ := ark.NewEmbedder(ctx, &ark.EmbeddingConfig{ APIKey: os.Getenv("ARK_API_KEY"), Region: os.Getenv("ARK_REGION"), Model: os.Getenv("ARK_MODEL"), }) // 4. Prepare documents // Documents usually contain at least an ID and Content. // You can also add extra metadata for filtering or other purposes. docs := []*schema.Document{ { ID: "1", Content: "Eiffel Tower: Located in Paris, France.", MetaData: map[string]any{ docExtraLocation: "France", }, }, { ID: "2", Content: "The Great Wall: Located in China.", MetaData: map[string]any{ docExtraLocation: "China", }, }, } // 5. Create ES indexer component indexer, _ := es7.NewIndexer(ctx, &es7.IndexerConfig{ Client: client, Index: indexName, IndexSpec: indexSpec, // Add this to enable automatic index creation BatchSize: 10, DocumentToFields: func(ctx context.Context, doc *schema.Document) (field2Value map[string]es7.FieldValue, err error) { return map[string]es7.FieldValue{ fieldContent: { Value: doc.Content, EmbedKey: fieldContentVector, // vectorize doc content and save vector to field "content_vector" }, fieldExtraLocation: { Value: doc.MetaData[docExtraLocation], }, }, nil }, Embedding: emb, }) // 6. Index documents ids, err := indexer.Store(ctx, docs) if err != nil { fmt.Printf("index error: %v\n", err) return } fmt.Println("indexed ids:", ids) } ``` -------------------------------- ### Install HTML Parser Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/parser/html/README.md Install the HTML parser component using go get. ```bash go get github.com/cloudwego/eino-ext/components/document/parser/html ``` -------------------------------- ### POST Request Example Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/httprequest/README.md Demonstrates how to execute a POST request with a specified URL and JSON body. The tool is initialized with a default configuration. ```go package main import ( "context" "fmt" "log" "time" "github.com/bytedance/sonic" post "github.com/cloudwego/eino-ext/components/tool/httprequest/post" ) func main() { config := &post.Config{} ctx := context.Background() tool, err := post.NewTool(ctx, config) if err != nil { log.Fatalf("Failed to create tool: %v", err) } request := &post.PostRequest{ URL: "https://jsonplaceholder.typicode.com/posts", Body: `{"title": "my title","body": "my body","userId": 1}`, } jsonReq, err := sonic.Marshal(request) if err != nil { log.Fatalf("Error marshaling JSON: %v", err) } resp, err := tool.InvokableRun(ctx, string(jsonReq)) if err != nil { log.Fatalf("Post failed: %v", err) } fmt.Println(resp) } ``` -------------------------------- ### Install URL Loader Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/loader/url/README.md Install the URL loader component using go get. ```bash go get github.com/cloudwego/eino-ext/components/document/loader/url ``` -------------------------------- ### Example with Custom Settings Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/transformer/splitter/semantic/README.md Illustrates initializing the semantic splitter with custom buffer size, minimum chunk size, separators, percentile, and a custom ID generator function. ```go splitter, err := semantic.NewSplitter(ctx, &semantic.Config{ Embedding: embedder, BufferSize: 2, MinChunkSize: 100, Separators: []string{"\n\n", "\n", ". ", "! ", "? "}, Percentile: 0.95, IDGenerator: func(ctx context.Context, originalID string, splitIndex int) string { return fmt.Sprintf("%s_semantic_%d", originalID, splitIndex) }, }) ``` -------------------------------- ### Quick Start URL Loader Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/loader/url/README.md Demonstrates how to initialize and use the URL loader to load a document from a given URI. ```go package main import ( "context" "log" "github.com/cloudwego/eino/components/document" "github.com/cloudwego/eino-ext/components/document/loader/url" ) func main() { ctx := context.Background() loader, err := url.NewLoader(ctx, &url.LoaderConfig{}) if err != nil { log.Fatalf("NewLoader failed, err=%v", err) } docs, err := loader.Load(ctx, document.Source{ URI: "https://example.com/page.html", }) if err != nil { log.Fatalf("Load failed, err=%v", err) } for _, doc := range docs { log.Printf("Content: %s\n", doc.Content) } } ``` -------------------------------- ### Install S3 Loader Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/loader/s3/README.md Install the S3 loader component using go get. ```bash go get github.com/cloudwego/eino-ext/components/document/loader/s3 ``` -------------------------------- ### Basic Local Backend Usage Source: https://github.com/cloudwego/eino-ext/blob/main/adk/backend/local/README.md Demonstrates initializing the local backend and performing basic file write and read operations. ```go import ( "context" "github.com/cloudwego/eino-ext/adk/backend/local" "github.com/cloudwego/eino/adk/middlewares/filesystem" ) // Initialize backend backend, err := local.NewBackend(context.Background(), &local.Config{}) if err != nil { panic(err) } // Write a file err = backend.Write(ctx, &filesystem.WriteRequest{ FilePath: "/path/to/file.txt", Content: "Hello, World!", }) // Read a file content, err := backend.Read(ctx, &filesystem.ReadRequest{ FilePath: "/path/to/file.txt", }) ``` -------------------------------- ### Install APMPlus Callback Source: https://github.com/cloudwego/eino-ext/blob/main/callbacks/apmplus/README.md Install the APMPlus callback package using go get. ```bash go get github.com/cloudwego/eino-ext/callbacks/apmplus ``` -------------------------------- ### Quick Start: Load Document from S3 Source: https://github.com/cloudwego/eino-ext/blob/main/components/document/loader/s3/README.md Demonstrates how to initialize the S3 loader with explicit credentials and load a document from an S3 URI. Ensure AWS credentials and region are correctly configured. ```go package main import ( "context" "log" "github.com/cloudwego/eino/components/document" "github.com/cloudwego/eino-ext/components/document/loader/s3" ) func main() { ctx := context.Background() region := "us-east-1" accessKey := "your-access-key" secretKey := "your-secret-key" loader, err := s3.NewS3Loader(ctx, &s3.LoaderConfig{ Region: ®ion, AWSAccessKey: &accessKey, AWSSecretKey: &secretKey, UseObjectKeyAsID: true, }) if err != nil { log.Fatalf("s3.NewS3Loader failed, err=%v", err) } docs, err := loader.Load(ctx, document.Source{ URI: "s3://my-bucket/path/to/document.txt", }) if err != nil { log.Fatalf("loader.Load failed, err=%v", err) } log.Printf("Loaded %d documents", len(docs)) log.Printf("Document content: %v", docs[0].Content) } ``` -------------------------------- ### Install Volcengine Ark Agentic Model Source: https://github.com/cloudwego/eino-ext/blob/main/components/model/agenticark/README.md Install the agenticark component using go get. ```bash go get github.com/cloudwego/eino-ext/components/model/agenticark@latest ``` -------------------------------- ### Install SearXNG Tool Source: https://github.com/cloudwego/eino-ext/blob/main/components/tool/searxng/README.md Install the SearXNG search tool package using go get. ```bash go get github.com/cloudwego/eino-ext/components/tool/searxng ``` -------------------------------- ### Quick Start: Index Documents with ES8 Source: https://github.com/cloudwego/eino-ext/blob/main/components/indexer/es8/README.md This example demonstrates how to set up and use the ES8 indexer to store documents in Elasticsearch. It includes client creation, index specification, embedding configuration, document preparation, and the indexing process. ```go import ( "context" "fmt" "log" "os" "github.com/cloudwego/eino/components/embedding" "github.com/cloudwego/eino/schema" "github.com/elastic/go-elasticsearch/v8" "github.com/cloudwego/eino-ext/components/embedding/ark" "github.com/cloudwego/eino-ext/components/indexer/es8" ) const ( indexName = "eino_example" fieldContent = "content" fieldContentVector = "content_vector" fieldExtraLocation = "location" docExtraLocation = "location" ) func main() { ctx := context.Background() username := os.Getenv("ES_USERNAME") password := os.Getenv("ES_PASSWORD") // Prepare CA certificate (ES8 enables TLS by default, provide CA for custom certs) httpCACertPath := os.Getenv("ES_HTTP_CA_CERT_PATH") var cert []byte if httpCACertPath != "" { var err error cert, err = os.ReadFile(httpCACertPath) if err != nil { log.Fatalf("read file failed, err=%v", err) } } // 1. Create ES client client, _ := elasticsearch.NewClient(elasticsearch.Config{ Addresses: []string{"https://localhost:9200"}, Username: username, Password: password, CACert: cert, }) // 2. Define Index Specification (Optional: automatically creates index if it doesn't exist) indexSpec := &es8.IndexSpec{ Settings: map[string]any{ "number_of_shards": 1, "number_of_replicas": 0, }, Mappings: map[string]any{ "properties": map[string]any{ fieldContentVector: map[string]any{ "type": "dense_vector", "dims": 1536, "index": true, "similarity": "l2_norm", }, }, }, } // 3. Create embedding component using ARK // Replace "ARK_API_KEY", "ARK_REGION", "ARK_MODEL" with your actual config emb, _ := ark.NewEmbedder(ctx, &ark.EmbeddingConfig{ APIKey: os.Getenv("ARK_API_KEY"), Region: os.Getenv("ARK_REGION"), Model: os.Getenv("ARK_MODEL"), }) // 4. Prepare documents // Documents usually contain at least an ID and Content. // You can also add extra metadata for filtering or other purposes. docs := []*schema.Document{ { ID: "1", Content: "Eiffel Tower: Located in Paris, France.", MetaData: map[string]any{ docExtraLocation: "France", }, }, { ID: "2", Content: "The Great Wall: Located in China.", MetaData: map[string]any{ docExtraLocation: "China", }, }, } // 5. Create ES indexer component indexer, _ := es8.NewIndexer(ctx, &es8.IndexerConfig{ Client: client, Index: indexName, IndexSpec: indexSpec, // Add this to enable automatic index creation BatchSize: 10, // DocumentToFields specifies how to map document fields to ES fields DocumentToFields: func(ctx context.Context, doc *schema.Document) (field2Value map[string]es8.FieldValue, err error) { return map[string]es8.FieldValue{ fieldContent: { Value: doc.Content, EmbedKey: fieldContentVector, // vectorize content and save to "content_vector" }, fieldExtraLocation: { // Extra metadata field Value: doc.MetaData[docExtraLocation], }, }, nil }, // Provide the embedding component to use for vectorization Embedding: emb, }) // 6. Index documents ids, err := indexer.Store(ctx, docs) if err != nil { fmt.Printf("index error: %v\n", err) return } fmt.Println("indexed ids:", ids) } ```