### Quick Start: Run a Basic Agent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo This example demonstrates how to initialize a Swarm client, create a simple agent, and run it with an initial message. Ensure you replace 'YOUR_OPENAI_API_KEY' with your actual OpenAI API key. ```go package main import ( "context" "fmt" "log" swarmgo "github.com/prathyushnallamothu/swarmgo" openai "github.com/sashabaranov/go-openai" llm "github.com/prathyushnallamothu/swarmgo/llm" ) func main() { client := swarmgo.NewSwarm("YOUR_OPENAI_API_KEY", llm.OpenAI) agent := &swarmgo.Agent{ Name: "Agent", Instructions: "You are a helpful assistant.", Model: "gpt-3.5-turbo", } messages := []openai.ChatCompletionMessage{ {Role: "user", Content: "Hello!"}, } ctx := context.Background() response, err := client.Run(ctx, agent, messages, nil, "", false, false, 5, true) if err != nil { log.Fatalf("Error: %v", err) } fmt.Println(response.Messages[len(response.Messages)-1].Content) } ``` -------------------------------- ### Install SwarmGo Package Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Use 'go get' to install the SwarmGo package. This command fetches and installs the specified package and its dependencies. ```bash go get github.com/prathyushnallamothu/swarmgo ``` -------------------------------- ### Run Demo Loop with Custom Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Starts an interactive CLI loop with custom configuration options. ```go func RunDemoLoopWithConfig(client *Swarm, agent *Agent, config *DemoLoopConfig) { // ... implementation details ... } ``` -------------------------------- ### Run Interactive Demo Loop Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Starts an interactive command-line interface (CLI) loop for conversing with an agent. ```go func RunDemoLoop(client *Swarm, agent *Agent) { // ... implementation details ... } ``` -------------------------------- ### Execute Graph Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Executes the workflow graph starting from its entry point with an initial state. ```go func (g *Graph) ExecuteGraph(ctx context.Context, initialState GraphState) (GraphState, error) ``` -------------------------------- ### Set Graph Entry Point Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Specifies the starting node for the workflow graph execution. ```go func (g *Graph) SetEntryPoint(nodeID NodeID) error ``` -------------------------------- ### Get All Step Results Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns all step results from the workflow execution. Added in v1.0.4. ```go func (wf *Workflow) GetAllStepResults() []StepResult ``` -------------------------------- ### Create Hierarchical Workflow in SwarmGo Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Illustrates the setup of a Hierarchical workflow, assigning agents to teams (manager, research, analysis), and establishing the agent connection hierarchy. ```go workflow := swarmgo.NewWorkflow(apiKey, llm.OpenAI, swarmgo.HierarchicalWorkflow) // Add agents to teams workflow.AddAgentToTeam(managerAgent, swarmgo.SupervisorTeam) workflow.AddAgentToTeam(researchAgent, swarmgo.ResearchTeam) workflow.AddAgentToTeam(analysisAgent, swarmgo.AnalysisTeam) // Connect agents in hierarchy workflow.ConnectAgents(managerAgent.Name, researchAgent.Name) workflow.ConnectAgents(researchAgent.Name, analysisAgent.Name) ``` -------------------------------- ### Implement Custom StreamHandler Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Create a custom StreamHandler to define specific behavior for streaming events. This example tracks total tokens and prints output. ```go type CustomStreamHandler struct { totalTokens int } func (h *CustomStreamHandler) OnStart() { fmt.Println("Starting stream...") } func (h *CustomStreamHandler) OnToken(token string) { h.totalTokens++ fmt.Print(token) } func (h *CustomStreamHandler) OnComplete(msg openai.ChatCompletionMessage) { fmt.Printf("\nComplete! Total tokens: %d\n", h.totalTokens) } func (h *CustomStreamHandler) OnError(err error) { fmt.Printf("Error: %v\n", err) } func (h *CustomStreamHandler) OnToolCall(tool openai.ToolCall) { fmt.Printf("\nUsing tool: %s\n", tool.Function.Name) } ``` -------------------------------- ### Execute Workflow Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Runs the workflow starting from a specified agent with a user request, returning detailed results. Added in v1.0.4. ```go func (wf *Workflow) Execute(startAgent string, userRequest string) (*WorkflowResult, error) ``` -------------------------------- ### Get All Agents Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Retrieves all agents currently in the workflow. Added in v1.0.4. ```go func (wf *Workflow) GetAgents() map[string]*Agent ``` -------------------------------- ### Agent.WithInstructions Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets static instructions for the agent, guiding its responses and behavior. ```APIDOC ## Agent.WithInstructions ### Description Sets the static instructions for the agent. ### Signature ```go func (a *Agent) WithInstructions(instructions string) *Agent ``` ``` -------------------------------- ### RunDemoLoop Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Starts an interactive command-line interface (CLI) loop for conversing with a specified agent. ```APIDOC ## RunDemoLoop ### Description RunDemoLoop starts an interactive CLI loop for conversing with an agent. ### Signature ```go func RunDemoLoop(client *Swarm, agent *Agent) ``` ``` -------------------------------- ### Get Workflow Connections Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns all connections between agents in the workflow. Added in v1.0.4. ```go func (wf *Workflow) GetConnections() map[string][]string ``` -------------------------------- ### Get Routing Log Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns the routing history of the workflow. Added in v1.0.4. ```go func (wf *Workflow) GetRoutingLog() []string ``` -------------------------------- ### Get Teams and Agents Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns a map of team types to slices of agents belonging to each team. Added in v1.0.4. ```go func (wf *Workflow) GetTeams() map[TeamType][]*Agent ``` -------------------------------- ### Get Default Demo Loop Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo DefaultDemoLoopConfig returns a pointer to a DemoLoopConfig struct initialized with default values for the demo loop. ```go func DefaultDemoLoopConfig() *DemoLoopConfig ``` -------------------------------- ### Execute Workflow Graph with GraphRunner Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Executes a registered workflow graph identified by graphID, starting with the provided initialState. Returns the final state and any errors encountered. ```go func (r *GraphRunner) ExecuteGraph(ctx context.Context, graphID string, initialState GraphState) (GraphState, error) ``` -------------------------------- ### Execute Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Executes the workflow starting from a specified agent, processing a user's request. Returns the workflow result, including detailed step outcomes, or an error if execution fails. Added in v1.0.4. ```APIDOC ## Execute ### Description Execute runs the workflow and returns detailed results including step outcomes. ### Method func (*Workflow) Execute(startAgent string, userRequest string) (*WorkflowResult, error) ``` -------------------------------- ### Initialize SwarmGo with LLM Provider Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Shows how to initialize a SwarmGo client with either OpenAI or Gemini as the language learning model provider. ```go // Initialize with OpenAI client := swarmgo.NewSwarm("YOUR_API_KEY", llm.OpenAI) ``` ```go // Initialize with Gemini client := swarmgo.NewSwarm("YOUR_API_KEY", llm.Gemini) ``` -------------------------------- ### Initialize Swarm with Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Swarm with custom configuration. Requires API key, LLM provider, and a Config pointer. ```go func NewSwarmWithConfig(apiKey string, provider llm.LLMProvider, config *Config) *Swarm ``` -------------------------------- ### Initialize Swarm with Host Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a Swarm instance with a custom host. Requires API key, host string, and an LLM provider. ```go func NewSwarmWithHost(apiKey, host string, provider llm.LLMProvider) *Swarm ``` -------------------------------- ### Get Recent Memories from MemoryStore Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Retrieves the 'n' most recently added memories from the MemoryStore. ```go func (ms *MemoryStore) GetRecentMemories(n int) []Memory ``` -------------------------------- ### Configure Agent with Static Instructions Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets the static instructions for an agent. ```go func (a *Agent) WithInstructions(instructions string) *Agent ``` -------------------------------- ### Run Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo The main entry point for agent execution. ```APIDOC ## Run ### Description Run is the main entry point for agent execution. ### Signature ```go func (s *Swarm) Run( ctx context.Context, agent *Agent, messages []llm.Message, contextVariables map[string]interface{}, modelOverride string, stream bool, debug bool, maxTurns int, executeTools bool, ) (Response, error) ``` ``` -------------------------------- ### Create an Agent Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Defines the basic structure of an agent, including its name, instructions (system prompt), and the OpenAI model to be used. ```go agent := &swarmgo.Agent{ Name: "Agent", Instructions: "You are a helpful assistant.", Model: "gpt-4o", } ``` -------------------------------- ### Initialize and Configure Collaborative Workflow Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Set up a new collaborative workflow with a specified API key and language model. Agents are then added to a 'DocumentTeam' and connected in a circular pattern for collaborative task processing. ```go workflow := swarmgo.NewWorkflow(apiKey, llm.OpenAI, swarmgo.CollaborativeWorkflow) // Add agents to document team workflow.AddAgentToTeam(editor, swarmgo.DocumentTeam) workflow.AddAgentToTeam(reviewer, swarmgo.DocumentTeam) workflow.AddAgentToTeam(writer, swarmgo.DocumentTeam) // Connect agents in collaborative pattern workflow.ConnectAgents(editor.Name, reviewer.Name) workflow.ConnectAgents(reviewer.Name, writer.Name) workflow.ConnectAgents(writer.Name, editor.Name) ``` -------------------------------- ### Get Current Agent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns the name of the currently active agent in the workflow. Added in v1.0.4. ```go func (wf *Workflow) GetCurrentAgent() string ``` -------------------------------- ### NewSwarmWithConfig Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Swarm with custom configuration. ```APIDOC ## NewSwarmWithConfig ### Description Initializes a new Swarm with custom configuration. ### Signature ```go func NewSwarmWithConfig(apiKey string, provider llm.LLMProvider, config *Config) *Swarm ``` ``` -------------------------------- ### Get Specific Step Result Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns the result of a specific step in the workflow by its number. Added in v1.0.4. ```go func (wf *Workflow) GetStepResult(stepNumber int) (*StepResult, error) ``` -------------------------------- ### Create New GraphBuilder Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new GraphBuilder with a name and description for the graph being built. ```go func NewGraphBuilder(name, description string) *GraphBuilder ``` -------------------------------- ### Get Last Step Result Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns the result of the last executed step in the workflow. Added in v1.0.4. ```go func (wf *Workflow) GetLastStepResult() (*StepResult, error) ``` -------------------------------- ### Create New Graph Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new workflow graph with a given name and description. ```go func NewGraph(name string, description string) *Graph ``` -------------------------------- ### Configure Agent with ClientConfig Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets the client configuration for an agent. ```go func (a *Agent) WithConfig(config *ClientConfig) *Agent ``` -------------------------------- ### Create Supervisor Workflow in SwarmGo Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Demonstrates setting up a Supervisor workflow, adding agents to specific teams (supervisor and worker), designating a team leader, and connecting agents for communication. ```go workflow := swarmgo.NewWorkflow(apiKey, llm.OpenAI, swarmgo.SupervisorWorkflow) // Add agents to teams workflow.AddAgentToTeam(supervisorAgent, swarmgo.SupervisorTeam) workflow.AddAgentToTeam(workerAgent1, swarmgo.WorkerTeam) workflow.AddAgentToTeam(workerAgent2, swarmgo.WorkerTeam) // Set supervisor as team leader workflow.SetTeamLeader(supervisorAgent.Name, swarmgo.SupervisorTeam) // Connect agents workflow.ConnectAgents(supervisorAgent.Name, workerAgent1.Name) workflow.ConnectAgents(supervisorAgent.Name, workerAgent2.Name) ``` -------------------------------- ### Stream Handler OnStart Method Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo OnStart is a method of DefaultStreamHandler called when a stream operation begins. It takes no arguments. ```go func (h *DefaultStreamHandler) OnStart() ``` -------------------------------- ### Get Team Leaders Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns a map of team types to their respective leader agent names. Added in v1.0.4. ```go func (wf *Workflow) GetTeamLeaders() map[TeamType]string ``` -------------------------------- ### Get Value from GraphState Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Retrieves a value from the GraphState using a StateKey. Includes type assertion to safely access the value. ```go func (s GraphState) Get(key StateKey) interface{} ``` -------------------------------- ### Define Agent Instructions with Context Variables Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Use context variables to dynamically set agent instructions. Ensure type assertion for context variables. ```go func instructions(contextVariables map[string]interface{}) string { name, ok := contextVariables["name"].(string) if !ok { name = "User" } return fmt.Sprintf("You are a helpful assistant. Greet the user by name (%s).", name) } agent.InstructionsFunc = instructions ``` -------------------------------- ### Get Default Swarm Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo DefaultConfig returns a pointer to a Config struct initialized with default Swarm configuration values. ```go func DefaultConfig() *Config ``` -------------------------------- ### NewSwarm Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Swarm instance with an LLM client. ```APIDOC ## NewSwarm ### Description Initializes a new Swarm instance with an LLM client. ### Signature ```go func NewSwarm(apiKey string, provider llm.LLMProvider) *Swarm ``` ``` -------------------------------- ### Configure and Run Agents Concurrently Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Set up multiple agents with their configurations (messages, max turns, tool execution) and run them in parallel using ConcurrentSwarm. Includes context-based timeout and error handling. ```go // Create a concurrent swarm cs := swarmgo.NewConcurrentSwarm(apiKey) // Configure multiple agents configs := map[string]swarmgo.AgentConfig{ "agent1": { Agent: agent1, Messages: []openai.ChatCompletionMessage{ {Role: openai.ChatMessageRoleUser, Content: "Task 1"}, }, MaxTurns: 1, ExecuteTools: true, }, "agent2": { Agent: agent2, Messages: []openai.ChatCompletionMessage{ {Role: openai.ChatMessageRoleUser, Content: "Task 2"}, }, MaxTurns: 1, ExecuteTools: true, }, } // Run agents concurrently with a timeout ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() results := cs.RunConcurrent(ctx, configs) // Process results for _, result := range results { if result.Error != nil { log.Printf("Error in %s: %v\n", result.AgentName, result.Error) continue } // Handle successful response fmt.Printf("Result from %s: %s\n", result.AgentName, result.Response) } ``` -------------------------------- ### NewSwarmWithHost Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a Swarm with a custom host. ```APIDOC ## NewSwarmWithHost ### Description Creates a Swarm with a custom host. ### Signature ```go func NewSwarmWithHost(apiKey, host string, provider llm.LLMProvider) *Swarm ``` ``` -------------------------------- ### Define StreamHandler Interface Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Represents a handler for streaming responses. Defines methods for start, token, tool call, completion, and error events. ```go type StreamHandler interface { OnStart() OnToken(token string) OnToolCall(toolCall llm.ToolCall) OnComplete(message llm.Message) OnError(err error) } ``` -------------------------------- ### Configure Agent with Dynamic Instructions Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets a function to dynamically generate instructions for an agent based on context variables. ```go func (a *Agent) WithInstructionsFunc(f func(map[string]interface{}) string) *Agent ``` -------------------------------- ### Build Workflow from Specification Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Constructs a concrete Workflow instance from a given WorkflowSpec. ```go func (dwc *DynamicWorkflowCreator) BuildWorkflow(spec *WorkflowSpec) (*Workflow, error) ``` -------------------------------- ### Get String Value from GraphState Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Retrieves a string value from the GraphState. Returns the string value and a second boolean indicating if the key was found and was of string type. ```go func (s GraphState) GetString(key StateKey) (string, bool) ``` -------------------------------- ### Get Boolean Value from GraphState Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Retrieves a boolean value from the GraphState. Returns the boolean value and a second boolean indicating if the key was found and was of boolean type. ```go func (s GraphState) GetBool(key StateKey) (bool, bool) ``` -------------------------------- ### Configure Agent with Functions Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets the list of functions that an agent can perform. ```go func (a *Agent) WithFunctions(functions []AgentFunction) *Agent ``` -------------------------------- ### Initialize New Swarm Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Swarm instance with an API key and an LLM provider. ```go func NewSwarm(apiKey string, provider llm.LLMProvider) *Swarm ``` -------------------------------- ### Initialize New Workflow Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Workflow instance with an API key and LLM provider. Added in v1.0.4. ```go func NewWorkflow(apikey string, provider llm.LLMProvider, workflowType WorkflowType) *Workflow ``` -------------------------------- ### Define StreamHandler Interface Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Implement the StreamHandler interface to process streaming responses. This interface includes methods for handling stream start, tokens, tool calls, completion, and errors. ```go type StreamHandler interface { OnStart() OnToken(token string) OnToolCall(toolCall openai.ToolCall) OnComplete(message openai.ChatCompletionMessage) OnError(err error) } ``` -------------------------------- ### NewOpenAILLMWithHost Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm NewOpenAILLMWithHost creates a new OpenAI LLM client with a specified host. It requires an API key. ```APIDOC ## NewOpenAILLMWithHost ### Description Creates a new OpenAI LLM client with a specified host. ### Parameters #### Path Parameters - **apiKey** (string) - Required - The API key for authenticating with the OpenAI service. - **host** (string) - Required - The host for the OpenAI service. ### Returns - *OpenAILLM - A pointer to the initialized OpenAILLM client. ``` -------------------------------- ### OpenAILLM Client Creation with Custom Host Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new OpenAI LLM client with a specified host, useful for custom endpoints or proxies. ```go func NewOpenAILLMWithHost(apiKey string, host string) *OpenAILLM ``` -------------------------------- ### Create and Execute Workflow Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo A convenience method to create and execute a workflow based on user tasks in a single step. ```go func (dwc *DynamicWorkflowCreator) CreateAndExecuteWorkflow(ctx context.Context, userTask string) (*WorkflowResult, error) ``` -------------------------------- ### Create New Agent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a new agent instance with an initialized memory store. ```go func NewAgent(name, model string, provider llm.LLMProvider) *Agent ``` -------------------------------- ### NewOpenAILLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new OpenAI LLM client. Requires an API key for authentication. ```APIDOC ## NewOpenAILLM ### Description Creates a new OpenAI LLM client. This function initializes the client with the provided API key. ### Method Signature ```go func NewOpenAILLM(apiKey string) *OpenAILLM ``` ### Parameters - `apiKey` (string): The API key for authenticating with the OpenAI service. ``` -------------------------------- ### OpenAILLM Client Creation Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new OpenAI LLM client. Requires an API key for authentication. ```go func NewOpenAILLM(apiKey string) *OpenAILLM ``` -------------------------------- ### RunDemoLoopWithConfig Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initiates an interactive CLI loop with custom configuration options for agent interaction. ```APIDOC ## RunDemoLoopWithConfig ### Description RunDemoLoopWithConfig starts an interactive CLI loop with custom configuration. ### Signature ```go func RunDemoLoopWithConfig(client *Swarm, agent *Agent, config *DemoLoopConfig) ``` ``` -------------------------------- ### Check Swarm Initialization Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns true if the Swarm instance is properly initialized, false otherwise. ```go func (s *Swarm) IsInitialized() bool ``` -------------------------------- ### NewOpenAILLMWithHost Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new OpenAI LLM client with a specified host. Allows overriding the default OpenAI API endpoint. ```APIDOC ## NewOpenAILLMWithHost ### Description Creates a new OpenAI LLM client, allowing the specification of a custom host (API endpoint). ### Method Signature ```go func NewOpenAILLMWithHost(apiKey string, host string) *OpenAILLM ``` ### Parameters - `apiKey` (string): The API key for authenticating with the OpenAI service. - `host` (string): The custom host or API endpoint to use for the OpenAI service. ``` -------------------------------- ### Swarm Initialization Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Provides functions to create new Swarm instances with different configuration options. ```APIDOC ## Swarm Initialization ### Description Functions to create and initialize a Swarm instance. ### Functions * **NewSwarm**: Creates a new Swarm instance with an API key and LLM provider. ```go func NewSwarm(apiKey string, provider llm.LLMProvider) *Swarm ``` * **NewSwarmWithConfig**: Creates a new Swarm instance with an API key, LLM provider, and custom configuration. ```go func NewSwarmWithConfig(apiKey string, provider llm.LLMProvider, config *Config) *Swarm ``` * **NewSwarmWithHost**: Creates a new Swarm instance specifying the API key, host, and LLM provider. ```go func NewSwarmWithHost(apiKey, host string, provider llm.LLMProvider) *Swarm ``` ``` -------------------------------- ### DeepSeekLLM Client Creation Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new DeepSeek LLM client. Requires an API key for authentication. ```go func NewDeepSeekLLM(apiKey string) *DeepSeekLLM ``` -------------------------------- ### NewGeminiLLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Gemini LLM client. Requires an API key and accepts optional configuration options. ```APIDOC ## NewGeminiLLM ### Description Creates a new Gemini LLM client. This function initializes the client with the provided API key and optional configuration settings. ### Method Signature ```go func NewGeminiLLM(apiKey string, opts ...GeminiOptions) (*GeminiLLM, error) ``` ### Parameters - `apiKey` (string): The API key for authenticating with the Gemini service. - `opts` (...GeminiOptions): Optional configuration options for the Gemini model. ``` -------------------------------- ### OllamaLLM Client Creation Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Ollama LLM client. For use with a default local Ollama instance. ```go func NewOllamaLLM() (*OllamaLLM, error) ``` -------------------------------- ### OllamaLLM Client Creation with Custom URL Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Ollama LLM client with a custom base URL, allowing connection to a remote Ollama instance. ```go func NewOllamaLLMWithURL(baseURL string) (*OllamaLLM, error) ``` -------------------------------- ### Generate Workflow Specification from Task Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Generates a workflow specification based on a user's task description. ```go func (dwc *DynamicWorkflowCreator) CreateWorkflowFromTask(ctx context.Context, userTask string) (*WorkflowSpec, error) ``` -------------------------------- ### Manage Agent Memory in SwarmGo Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Demonstrates creating an agent with memory, explicitly storing memories with context and importance, and retrieving/searching memories. ```go import "time" // Create a new agent with memory capabilities agent := swarmgo.NewAgent("MyAgent", "gpt-4") // Memory is automatically managed for conversations and tool calls // You can also explicitly store memories: memory := swarmgo.Memory{ Content: "User prefers dark mode", Type: "preference", Context: map[string]interface{}{"setting": "ui"}, Timestamp: time.Now(), Importance: 0.8, } agent.Memory.AddMemory(memory) // Retrieve recent memories recentMemories := agent.Memory.GetRecentMemories(5) // Search specific types of memories preferences := agent.Memory.SearchMemories("preference", nil) ``` -------------------------------- ### Workflow Initialization Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Functions to create new Workflow instances. ```APIDOC ## Workflow Initialization ### Description Functions to create and initialize a Workflow instance. ### Functions * **NewWorkflow**: Creates a new Workflow instance with an API key, LLM provider, and workflow type. ```go func NewWorkflow(apikey string, provider llm.LLMProvider, workflowType WorkflowType) *Workflow ``` ``` -------------------------------- ### Create New Claude LLM Client Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Claude LLM client. Requires an API key for authentication. ```go func NewClaudeLLM(apiKey string) *ClaudeLLM ``` -------------------------------- ### OllamaLLM CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for Ollama chat completions. ```go func (o *OllamaLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` -------------------------------- ### Run Agent Execution Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo The main entry point for agent execution. Manages the workflow with options for context, messages, variables, model override, streaming, debugging, max turns, and tool execution. ```go func (s *Swarm) Run( ctx context.Context, agent *Agent, messages []llm.Message, contextVariables map[string]interface{}, modelOverride string, stream bool, debug bool, maxTurns int, executeTools bool, ) (Response, error) ``` -------------------------------- ### NewGeminiLLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm NewGeminiLLM creates a new Gemini LLM client. It requires an API key and optional configuration options. ```APIDOC ## NewGeminiLLM ### Description Creates a new Gemini LLM client. ### Parameters #### Path Parameters - **apiKey** (string) - Required - The API key for authenticating with the Gemini service. - **opts** (...GeminiOptions) - Optional - Additional configuration options for the Gemini client. ### Returns - **(*GeminiLLM, error)** - A pointer to the initialized GeminiLLM client and an error if initialization fails. ``` -------------------------------- ### GeminiLLM Client Creation Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Gemini LLM client. Accepts an API key and optional configuration options. ```go func NewGeminiLLM(apiKey string, opts ...GeminiOptions) (*GeminiLLM, error) ``` -------------------------------- ### NewDeepSeekLLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new DeepSeek LLM client. Requires an API key for authentication. ```APIDOC ## NewDeepSeekLLM ### Description Creates a new DeepSeek LLM client. This function initializes the client with the provided API key. ### Method Signature ```go func NewDeepSeekLLM(apiKey string) *DeepSeekLLM ``` ### Parameters - `apiKey` (string): The API key for authenticating with the DeepSeek service. ``` -------------------------------- ### GeminiLLM CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for Gemini chat completions. ```go func (g *GeminiLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` -------------------------------- ### Create Human Input Node Function Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a node that collects input from a human user. Requires graph, ID, and a prompt string. ```go func CreateHumanInputNode(g *Graph, id NodeID, prompt string) *Node ``` -------------------------------- ### Configure LLM Client Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo ClientConfig holds settings for connecting to a Language Model (LLM) provider. It includes authentication, base URL, and model mapping. ```go type ClientConfig struct { Provider llm.LLMProvider AuthToken string BaseURL string OrgID string APIVersion string AssistantVersion string ModelMapperFunc func(model string) string // replace model to provider-specific deployment name HTTPClient *http.Client EmptyMessagesLimit uint Options map[string]interface{} // Additional provider-specific options } ``` -------------------------------- ### NewWorkflow Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new Workflow instance with the provided API key, LLM provider, and workflow type. Added in v1.0.4. ```APIDOC ## NewWorkflow ### Description NewWorkflow initializes a new Workflow instance. ### Method func NewWorkflow(apikey string, provider llm.LLMProvider, workflowType WorkflowType) *Workflow ``` -------------------------------- ### IsInitialized Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns whether the Swarm is properly initialized. ```APIDOC ## IsInitialized ### Description Returns whether the Swarm is properly initialized. ### Signature ```go func (s *Swarm) IsInitialized() bool ``` ``` -------------------------------- ### OllamaLLM CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for Ollama streaming. ```go func (o *OllamaLLM) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (ChatCompletionStream, error) ``` -------------------------------- ### Use Streaming Response with Custom Handler Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initiate a streaming response from a client by providing an agent, messages, and a custom StreamHandler. Ensure the API key and model are correctly configured. ```go client := swarmgo.NewSwarm("YOUR_OPENAI_API_KEY", llm.OpenAI) agent := &swarmgo.Agent{ Name: "FileAnalyzer", Instructions: "You are an assistant that analyzes files.", Model: "gpt-4", } handler := &CustomStreamHandler{} er := client.StreamingResponse( context.Background(), agent, messages, nil, "", handler, true, ) ``` -------------------------------- ### NewAgent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a new agent with a specified name, model, and LLM provider, initializing its memory store. ```APIDOC ## NewAgent ### Description Creates a new agent with initialized memory store. ### Signature ```go func NewAgent(name, model string, provider llm.LLMProvider) *Agent ``` ``` -------------------------------- ### OllamaLLM.CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a chat completion with the Ollama LLM. Implements the LLM interface for Ollama. ```APIDOC ## OllamaLLM.CreateChatCompletion ### Description Creates a chat completion using the Ollama LLM. This method adheres to the `LLM` interface for Ollama. ### Method Signature ```go func (o *OllamaLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` ### Parameters - `ctx` (context.Context): The context for the request. - `req` (ChatCompletionRequest): The request object containing chat completion parameters. ``` -------------------------------- ### Implement Agent Handoff Function Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Create a function to transfer conversations to another agent. This function should return a swarmgo.Result with the target agent. ```go func transferToAnotherAgent(args map[string]interface{}, contextVariables map[string]interface{}) swarmgo.Result { anotherAgent := &swarmgo.Agent{ Name: "AnotherAgent", Instructions: "You are another agent.", Model: "gpt-3.5-turbo", } return swarmgo.Result{ Agent: anotherAgent, Value: "Transferring to AnotherAgent.", } } ``` -------------------------------- ### Define a Tool Function for an Agent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Illustrates how to define a Go function that can be used as a tool by an agent. The function accepts arguments and context variables, and returns a SwarmGo Result. ```go func getWeather(args map[string]interface{}, contextVariables map[string]interface{}) swarmgo.Result { location := args["location"].(string) // Simulate fetching weather data return swarmgo.Result{ Value: fmt.Sprintf(`{"temp": 67, "unit": "F", "location": "%s"}`, location), } } ``` -------------------------------- ### Create New DynamicWorkflowCreator Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Initializes a new DynamicWorkflowCreator with an API key and an LLM provider. ```go func NewDynamicWorkflowCreator(apiKey string, provider llm.LLMProvider) *DynamicWorkflowCreator ``` -------------------------------- ### Create Concurrent Swarm Instance Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo NewConcurrentSwarm initializes a new ConcurrentSwarm with the provided API key and LLM provider. ```go func NewConcurrentSwarm(apiKey string, provider llm.LLMProvider) *ConcurrentSwarm ``` -------------------------------- ### DeepSeekLLM CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for DeepSeek chat completions. ```go func (l *DeepSeekLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` -------------------------------- ### Demo Loop Configuration Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo DemoLoopConfig holds settings for controlling the behavior of a demo loop, such as timeouts, history management, and output formatting. ```go type DemoLoopConfig struct { Timeout time.Duration // Timeout for each agent execution MaxHistoryMessages int // Maximum number of messages to keep in history MaxInputLength int // Maximum length of user input ShowFunctionResults bool // Whether to display function results ColorOutput bool // Whether to use color in output Debug bool // Whether to show debug information SaveHistory bool // Whether to save conversation history to file HistoryFile string // Path to file for saving history } ``` -------------------------------- ### Create New MemoryStore Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Factory function to create a new MemoryStore instance. Allows specifying the maximum capacity for short-term memory. ```go func NewMemoryStore(maxShortTerm int) *MemoryStore ``` -------------------------------- ### NewOpenAILLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm NewOpenAILLM creates a new OpenAI LLM client. It requires an API key for authentication. ```APIDOC ## NewOpenAILLM ### Description Creates a new OpenAI LLM client. ### Parameters #### Path Parameters - **apiKey** (string) - Required - The API key for authenticating with the OpenAI service. ### Returns - *OpenAILLM - A pointer to the initialized OpenAILLM client. ``` -------------------------------- ### DefaultDemoLoopConfig Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Returns default configuration for the demo loop. ```APIDOC ## DefaultDemoLoopConfig ### Description Returns default configuration for demo loop. ### Signature ```go func DefaultDemoLoopConfig() *DemoLoopConfig ``` ``` -------------------------------- ### GeminiLLM CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for Gemini streaming. ```go func (g *GeminiLLM) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (ChatCompletionStream, error) ``` -------------------------------- ### GraphRunner Methods Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Methods for creating, registering, and executing graphs. ```APIDOC ## NewGraphRunner ### Description Creates a new graph runner. ### Signature ```go func NewGraphRunner() *GraphRunner ``` ``` ```APIDOC ## GraphRunner.ExecuteGraph ### Description Runs a graph with the given initial state. ### Signature ```go func (r *GraphRunner) ExecuteGraph(ctx context.Context, graphID string, initialState GraphState) (GraphState, error) ``` ``` ```APIDOC ## GraphRunner.RegisterGraph ### Description Adds a graph to the runner. ### Signature ```go func (r *GraphRunner) RegisterGraph(graph *Graph) ``` ``` -------------------------------- ### LLMProvider Constants Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Defines constants for different LLM providers. ```go type LLMProvider string const ( OpenAI LLMProvider = "OPEN_AI" Azure LLMProvider = "AZURE" AzureAD LLMProvider = "AZURE_AD" CloudflareAzure LLMProvider = "CLOUDFLARE_AZURE" Gemini LLMProvider = "GEMINI" Claude LLMProvider = "CLAUDE" Ollama LLMProvider = "OLLAMA" DeepSeek LLMProvider = "DEEPSEEK" ) ``` -------------------------------- ### Set Graph Entry Point with GraphBuilder Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets the designated entry point for the workflow graph. Only one entry point is typically allowed. ```go func (b *GraphBuilder) WithEntryPoint(nodeID NodeID) *GraphBuilder ``` -------------------------------- ### Create Agent Node Function Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Helper function to create common agent node types. Requires graph, ID, name, instructions, model, functions, and LLM provider. ```go func CreateAgentNode(g *Graph, id NodeID, name string, instructions string, model string, functions []AgentFunction, provider llm.LLMProvider) *Node ``` -------------------------------- ### Run Agent with Messages Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Executes an agent with a given set of messages and retrieves the response. This method handles the interaction with the LLM based on the agent's configuration. ```go messages := []openai.ChatCompletionMessage{ {Role: "user", Content: "Hello!"}, } ctx := context.Background() response, err := client.Run(ctx, agent, messages, nil, "", false, false, 5, true) if err != nil { log.Fatalf("Error: %v", err) } fmt.Println(response.Messages[len(response.Messages)-1].Content) ``` -------------------------------- ### Set Cycle Handling Strategy Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Configures how the workflow should handle detected cycles. Added in v1.0.4. ```go func (wf *Workflow) SetCycleHandling(handling CycleHandling) ``` -------------------------------- ### Agent.WithConfig Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Sets the configuration for an agent, allowing customization of its behavior and parameters. ```APIDOC ## Agent.WithConfig ### Description Sets the configuration for the agent. ### Signature ```go func (a *Agent) WithConfig(config *ClientConfig) *Agent ``` ``` -------------------------------- ### Create New GraphRunner Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Factory function to instantiate a new GraphRunner. Initializes the runner for graph execution. ```go func NewGraphRunner() *GraphRunner ``` -------------------------------- ### NewOllamaLLM Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a new Ollama LLM client. This function initializes the client with default settings. ```APIDOC ## NewOllamaLLM ### Description Creates a new Ollama LLM client using default configuration. ### Method Signature ```go func NewOllamaLLM() (*OllamaLLM, error) ``` ### Returns - `*OllamaLLM`: A pointer to the initialized OllamaLLM client. - `error`: An error if the client creation fails. ``` -------------------------------- ### MemoryStore Methods Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Methods for managing agent memories, including adding, retrieving, searching, and persisting memories. ```APIDOC ## NewMemoryStore ### Description Creates a new memory store with default settings. ### Signature ```go func NewMemoryStore(maxShortTerm int) *MemoryStore ``` ``` ```APIDOC ## MemoryStore.AddMemory ### Description Adds a new memory to both short and long-term storage. ### Signature ```go func (ms *MemoryStore) AddMemory(memory Memory) ``` ``` ```APIDOC ## MemoryStore.GetRecentMemories ### Description Retrieves the n most recent memories. ### Signature ```go func (ms *MemoryStore) GetRecentMemories(n int) []Memory ``` ``` ```APIDOC ## MemoryStore.LoadMemories ### Description Loads memories from JSON data. ### Signature ```go func (ms *MemoryStore) LoadMemories(data []byte) error ``` ``` ```APIDOC ## MemoryStore.SearchMemories ### Description Searches for memories based on type and context. ### Signature ```go func (ms *MemoryStore) SearchMemories(memoryType string, context map[string]interface{}) []Memory ``` ``` ```APIDOC ## MemoryStore.SerializeMemories ### Description Serializes all memories to JSON. ### Signature ```go func (ms *MemoryStore) SerializeMemories() ([]byte, error) ``` ``` -------------------------------- ### DeepSeekLLM CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for DeepSeek streaming. ```go func (l *DeepSeekLLM) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (ChatCompletionStream, error) ``` -------------------------------- ### GeminiOptions Structure Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Contains configuration options for the Gemini model, including model name, harm thresholds, and safety settings. ```go type GeminiOptions struct { Model string HarmThreshold genai.HarmBlockThreshold SafetySettings []*genai.SafetySetting } ``` -------------------------------- ### Swarm Configuration Options Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Config holds various settings for the Swarm, including retry logic, timeouts, token limits, and failure handling strategies. ```go type Config struct { MaxRetries int RetryBackoff time.Duration RequestTimeout time.Duration MaxTokens int DefaultModel string Debug bool LogLevel LogLevel TokenLimits map[string]int // Model-specific token limits FailureHandlers []FailureHandler RateLimitStrategy RateLimitStrategy } ``` -------------------------------- ### OpenAILLM.CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm CreateChatCompletion implements the LLM interface for OpenAI. It sends a chat completion request and returns the response. ```APIDOC ## OpenAILLM.CreateChatCompletion ### Description Implements the LLM interface for OpenAI to create a chat completion. ### Method - OpenAILLM.CreateChatCompletion ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - The context for the request. - **req** (ChatCompletionRequest) - Required - The chat completion request object. ### Returns - **ChatCompletionResponse** - The response from the chat completion. - **error** - An error if the request fails. ``` -------------------------------- ### GeminiLLM.CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a chat completion with the Gemini LLM. Implements the LLM interface for Gemini. ```APIDOC ## GeminiLLM.CreateChatCompletion ### Description Creates a chat completion using the Gemini LLM. This method adheres to the `LLM` interface for Gemini. ### Method Signature ```go func (g *GeminiLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` ### Parameters - `ctx` (context.Context): The context for the request. - `req` (ChatCompletionRequest): The request object containing chat completion parameters. ``` -------------------------------- ### ClaudeLLM CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Implements the LLM interface for Claude streaming. ```go func (c *ClaudeLLM) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (ChatCompletionStream, error) ``` -------------------------------- ### Add a Function (Tool) to an Agent Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Configures an agent to use a specific function by providing its name, description, parameters schema, and the function implementation. This allows the agent to call the defined function when needed. ```go agent.Functions = []swarmgo.AgentFunction{ { Name: "getWeather", Description: "Get the current weather in a given location.", Parameters: map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ "location": map[string]interface{}{ "type": "string", "description": "The city to get the weather for.", }, }, "required": []interface{}{"location"}, }, Function: getWeather, }, } ``` -------------------------------- ### DeepSeekLLM.CreateChatCompletion Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a chat completion with the DeepSeek LLM. Implements the LLM interface for DeepSeek. ```APIDOC ## DeepSeekLLM.CreateChatCompletion ### Description Creates a chat completion using the DeepSeek LLM. This method adheres to the `LLM` interface for DeepSeek. ### Method Signature ```go func (l *DeepSeekLLM) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error) ``` ### Parameters - `ctx` (context.Context): The context for the request. - `req` (ChatCompletionRequest): The request object containing chat completion parameters. ``` -------------------------------- ### OllamaLLM.CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm Creates a chat completion stream with the Ollama LLM. Implements the LLM interface for Ollama streaming. ```APIDOC ## OllamaLLM.CreateChatCompletionStream ### Description Creates a chat completion stream with the Ollama LLM. This method implements the `LLM` interface for handling streaming responses from Ollama. ### Method Signature ```go func (o *OllamaLLM) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (ChatCompletionStream, error) ``` ### Parameters - `ctx` (context.Context): The context for the request. - `req` (ChatCompletionRequest): The request object containing chat completion parameters. ``` -------------------------------- ### Create Router Node Function Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Creates a node that routes to different destinations based on content. Requires graph, ID, and a map of destination names to NodeIDs. ```go func CreateRouterNode(g *Graph, id NodeID, destinations map[string]NodeID) *Node ``` -------------------------------- ### Agent Struct Definition Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Defines the Agent structure, including its name, model, provider, configuration, instructions, functions, memory, and tool call settings. ```go type Agent struct { Name string // The name of the agent. Model string // The model identifier. Provider llm.LLMProvider // The LLM provider to use. Config *ClientConfig // Provider-specific configuration. Instructions string // Static instructions for the agent. InstructionsFunc func(contextVariables map[string]interface{}) string // Function to generate dynamic instructions based on context. Functions []AgentFunction // A list of functions the agent can perform. Memory *MemoryStore // Memory store for the agent. ParallelToolCalls bool // Whether to allow parallel tool calls. } ``` -------------------------------- ### Workflow Structure Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Represents a collection of agents and their connections. Added in v1.0.4. ```go type Workflow struct { // contains filtered or unexported fields } ``` -------------------------------- ### Run Agents Concurrently in Order Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo RunConcurrentOrdered executes agents concurrently but returns results in the order specified by the input configuration slice. ```go func (cs *ConcurrentSwarm) RunConcurrentOrdered(ctx context.Context, orderedConfigs []struct { Name string Config AgentConfig }) []ConcurrentResult ``` -------------------------------- ### OllamaLLM.CreateChatCompletionStream Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo/llm CreateChatCompletionStream implements the LLM interface for Ollama for streaming chat completions. ```APIDOC ## OllamaLLM.CreateChatCompletionStream ### Description Implements the LLM interface for Ollama to create a streaming chat completion. ### Method - OllamaLLM.CreateChatCompletionStream ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - The context for the request. - **req** (ChatCompletionRequest) - Required - The chat completion request object. ### Returns - **ChatCompletionStream** - An interface for receiving streaming chat completion responses. - **error** - An error if the request fails. ``` -------------------------------- ### Build Graph from Builder Source: https://pkg.go.dev/github.com/prathyushnallamothu/swarmgo Finalizes the graph construction and returns the built Graph object. ```go func (b *GraphBuilder) Build() *Graph ```