@@ -95,7 +95,14 @@ func WithToolsetRegistry(registry *ToolsetRegistry) Opt {
9595 }
9696}
9797
98+ // Load loads an agent team from the given file path.
99+ // Prefers LoadFrom for more control over the source.
98100func Load (ctx context.Context , p string , runtimeConfig config.RuntimeConfig , opts ... Opt ) (* team.Team , error ) {
101+ return LoadFrom (ctx , NewFileSource (p ), runtimeConfig , opts ... )
102+ }
103+
104+ // LoadFrom loads an agent team from the given source
105+ func LoadFrom (ctx context.Context , source AgentSource , runtimeConfig config.RuntimeConfig , opts ... Opt ) (* team.Team , error ) {
99106 var loadOpts loadOptions
100107 loadOpts .toolsetRegistry = NewDefaultToolsetRegistry ()
101108
@@ -105,8 +112,8 @@ func Load(ctx context.Context, p string, runtimeConfig config.RuntimeConfig, opt
105112 }
106113 }
107114
108- fileName := filepath . Base ( p )
109- parentDir := filepath . Dir ( p )
115+ fileName := source . Name ( )
116+ parentDir := source . ParentDir ( )
110117
111118 // Make env file paths absolute relative to the agent config file.
112119 var err error
@@ -127,12 +134,12 @@ func Load(ctx context.Context, p string, runtimeConfig config.RuntimeConfig, opt
127134 env := environment .NewMultiProvider (envFilesProviders , defaultEnvProvider )
128135
129136 // Load the agent's configuration
130- fs , err := os . OpenRoot ( parentDir )
137+ data , err := source . Read ( )
131138 if err != nil {
132- return nil , fmt .Errorf ("opening filesystem %s : %w" , parentDir , err )
139+ return nil , fmt .Errorf ("reading config file : %w" , err )
133140 }
134141
135- cfg , err := config .LoadConfig ( fileName , fs )
142+ cfg , err := config .LoadConfigBytes ( data )
136143 if err != nil {
137144 return nil , err
138145 }
0 commit comments