Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions pkg/server/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ type SessionManager struct {
sessionStore session.Store
Sources config.Sources

// TODO: We have to do something about this, it's weird, session creation should send everything that is needed.
// This is only used for the working directory...
runConfig *config.RuntimeConfig

refreshInterval time.Duration
Expand Down Expand Up @@ -614,16 +612,13 @@ func (sm *SessionManager) RunSession(ctx context.Context, sessionID, agentFilena
return nil, err
}

rc := sm.runConfig.Clone()
rc.WorkingDir = sess.WorkingDir

runtimeSession, exists := sm.runtimeSessions.Load(sessionID)

streamCtx, cancel := context.WithCancel(ctx)
var titleGen *sessiontitle.Generator
if !exists {
var rt runtime.Runtime
rt, titleGen, err = sm.runtimeForSession(ctx, sess, agentFilename, currentAgent, rc)
rt, titleGen, err = sm.runtimeForSession(ctx, sess, agentFilename, currentAgent, sm.runConfig)
if err != nil {
cancel()
return nil, err
Expand Down Expand Up @@ -1036,7 +1031,7 @@ func (sm *SessionManager) runtimeForSession(ctx context.Context, sess *session.S
span.End()
}()

loadResult, err := sm.loadTeamWithConfig(ctx, agentFilename, rc)
loadResult, err := sm.loadTeamWithConfig(ctx, agentFilename, rc, teamloader.WithWorkingDir(sess.WorkingDir))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -1112,13 +1107,14 @@ func (sm *SessionManager) loadTeam(ctx context.Context, agentFilename string, ru

// loadTeamWithConfig is like loadTeam but also returns the loaded model and
// provider configuration so the runtime can be wired for model switching.
func (sm *SessionManager) loadTeamWithConfig(ctx context.Context, agentFilename string, runConfig *config.RuntimeConfig) (*teamloader.LoadResult, error) {
func (sm *SessionManager) loadTeamWithConfig(ctx context.Context, agentFilename string, runConfig *config.RuntimeConfig, opts ...teamloader.Opt) (*teamloader.LoadResult, error) {
agentSource, err := sm.resolveSource(agentFilename)
if err != nil {
return nil, err
}

return teamloader.LoadWithConfig(ctx, agentSource, runConfig, loaderdefaults.Opts()...)
allOpts := append(loaderdefaults.Opts(), opts...)
return teamloader.LoadWithConfig(ctx, agentSource, runConfig, allOpts...)
}

// resolveSource looks up the agent source for agentFilename.
Expand Down
13 changes: 11 additions & 2 deletions pkg/teamloader/teamloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
var defaultMaxTokens int64 = 32000

type loadOptions struct {
workingDir string
modelOverrides []string
promptFiles []string
toolsetRegistry ToolsetRegistry
Expand All @@ -51,6 +52,13 @@ type loadOptions struct {

type Opt func(*loadOptions) error

func WithWorkingDir(dir string) Opt {
return func(opts *loadOptions) error {
opts.workingDir = dir
return nil
}
}

func WithModelOverrides(overrides []string) Opt {
return func(opts *loadOptions) error {
opts.modelOverrides = overrides
Expand Down Expand Up @@ -226,7 +234,8 @@ func LoadWithConfig(ctx context.Context, agentSource config.Source, runConfig *c
runConfig.ProviderRegistry = loadOpts.providerRegistry

// Load agents
parentDir := cmp.Or(agentSource.ParentDir(), runConfig.WorkingDir)
workingDir := cmp.Or(loadOpts.workingDir, runConfig.WorkingDir)
parentDir := cmp.Or(agentSource.ParentDir(), workingDir)
configName := configNameFromSource(agentSource.Name())
var agents []*agent.Agent
agentsByName := make(map[string]*agent.Agent)
Expand Down Expand Up @@ -358,7 +367,7 @@ func LoadWithConfig(ctx context.Context, agentSource config.Source, runConfig *c
// always exposed and never subject to the include filter.
loadedSkills = append(loadedSkills, inlineSkills(agentConfig.Skills.Inline)...)
if len(loadedSkills) > 0 {
skillSet := skillstool.New(loadedSkills, runConfig.WorkingDir)
skillSet := skillstool.New(loadedSkills, workingDir)
// Resolve the additional toolsets each fork skill exposes in
// its sub-session from the top-level toolsets section.
forkToolSets, forkWarnings := forkSkillToolSets(ctx, cfg, &agentConfig, loadedSkills, parentDir, runConfig, loadOpts.toolsetRegistry, configName, expander)
Expand Down