Skip to content

Commit 1c1c860

Browse files
LocalAI [bot]localai-bot
andauthored
feat: Add SUB_AGENT_BACKGROUND_DEFAULT environment variable (#26)
* feat: add sub-agent MCP server with background processing support - Implements sub_agent_chat tool for synchronous and asynchronous chat completions - Adds sub_agent_list tool to list active background tasks - Adds sub_agent_get_result tool to retrieve task results - Supports TTL-based cleanup for background tasks - Configurable via environment variables: - OPENAI_BASE_URL: Base URL for OpenAI API - OPENAI_MODEL: Model to use (default: gpt-4o-mini) - OPENAI_API_KEY: API key for authentication - SUB_AGENT_TTL: TTL in hours for task results (default: 4) * feat: add SUB_AGENT_BACKGROUND_DEFAULT environment variable - Add SUB_AGENT_BACKGROUND_DEFAULT env var reading in initConfig() - When set to 'true', background processing becomes the default - Request-level 'background' parameter can still override the default - Updated jsonschema description to reflect new default behavior Signed-off-by: team-coding-agent-1 <[email protected]> Signed-off-by: localai-bot <[email protected]> * Remove binary file as requested * Rebase: update sub-agent files to resolve conflicts with upstream/master * feat: add SUB_AGENT_BACKGROUND_DEFAULT environment variable - Add strconv import for parsing boolean environment variable - Add backgroundDefault package-level variable - Read SUB_AGENT_BACKGROUND_DEFAULT environment variable in init() - Update SendInput jsonschema description to reflect new default behavior - Use backgroundDefault as default, with request-level override capability - Follows existing pattern similar to SUB_AGENT_TTL configuration Signed-off-by: localai-bot <[email protected]> * fix: remove sub-agent go.mod and go.sum, use root go.mod instead --------- Signed-off-by: team-coding-agent-1 <[email protected]> Signed-off-by: localai-bot <[email protected]> Co-authored-by: localai-bot <[email protected]>
1 parent 06147e2 commit 1c1c860

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

sub-agent/main.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"log"
66
"os"
7+
"strconv"
78
"sync"
89
"time"
910

@@ -98,12 +99,19 @@ func (s *SubAgentStore) List() []*SubAgentResult {
9899
}
99100

100101
var (
101-
store *SubAgentStore
102-
openaiClient *openai.Client
103-
openaiModel string
102+
store *SubAgentStore
103+
openaiClient *openai.Client
104+
openaiModel string
105+
backgroundDefault bool
104106
)
105107

106108
func init() {
109+
// SUB_AGENT_BACKGROUND_DEFAULT can be "true" or "false"
110+
backgroundDefault = false
111+
if bgEnv := os.Getenv("SUB_AGENT_BACKGROUND_DEFAULT"); bgEnv != "" {
112+
backgroundDefault, _ = strconv.ParseBool(bgEnv)
113+
}
114+
107115
// Initialize TTL (default 1 hour)
108116
ttl := 1 * time.Hour
109117
if ttlStr := os.Getenv("TTL"); ttlStr != "" {
@@ -134,7 +142,7 @@ func init() {
134142
// SendInput represents the input for sub_agent_send
135143
type SendInput struct {
136144
Message string `json:"message" jsonschema:"the message to send to the OpenAI endpoint"`
137-
Background bool `json:"background,omitempty" jsonschema:"whether to run the request in the background (default: false)"`
145+
Background bool `json:"background,omitempty" jsonschema:"whether to process in background (defaults to SUB_AGENT_BACKGROUND_DEFAULT env var, or false if not set)"`
138146
Model string `json:"model,omitempty" jsonschema:"override the default model for this request"`
139147
}
140148

@@ -195,7 +203,13 @@ func SendChatCompletion(ctx context.Context, req *mcp.CallToolRequest, input Sen
195203
result = resp.Choices[0].Message.Content
196204
}
197205

198-
if input.Background {
206+
// Use backgroundDefault as the default, but allow request-level override
207+
background := input.Background
208+
if !input.Background && backgroundDefault {
209+
// If request doesn't explicitly set background, use the default
210+
background = backgroundDefault
211+
}
212+
if background {
199213
taskID := uuid.New().String()
200214
subResult := &SubAgentResult{
201215
ID: taskID,

0 commit comments

Comments
 (0)