RegisterColab registers a Colab agent that executes a local Python file on a remote Colab session via the colab CLI.
(cfg config.ColabAgentConfig)
| 145 | // RegisterColab registers a Colab agent that executes a local Python file |
| 146 | // on a remote Colab session via the colab CLI. |
| 147 | func (r *Registry) RegisterColab(cfg config.ColabAgentConfig) error { |
| 148 | r.mu.Lock() |
| 149 | defer r.mu.Unlock() |
| 150 | |
| 151 | if err := validateID(cfg.ID); err != nil { |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | if _, ok := r.agents[cfg.ID]; ok { |
| 156 | return fmt.Errorf("agent %s already registered", cfg.ID) |
| 157 | } |
| 158 | |
| 159 | colabAgent, err := expagent.NewColabAgent(expagent.ColabAgentConfig{ |
| 160 | ID: cfg.ID, |
| 161 | LocalFile: cfg.LocalFile, |
| 162 | DriveFile: cfg.DriveFile, |
| 163 | Accelerator: cfg.Accelerator, |
| 164 | DriveMountPath: cfg.DriveMountPath, |
| 165 | Requirements: cfg.Requirements, |
| 166 | InputFlag: cfg.InputFlag, |
| 167 | OutputImage: cfg.OutputImage, |
| 168 | OutputDrivePath: cfg.OutputDrivePath, |
| 169 | }) |
| 170 | if err != nil { |
| 171 | return fmt.Errorf("failed to create colab agent: %w", err) |
| 172 | } |
| 173 | |
| 174 | r.agents[cfg.ID] = colabAgent |
| 175 | r.agentInfo[cfg.ID] = &agent.AgentInfo{ |
| 176 | ID: cfg.ID, |
| 177 | Name: cfg.Name, |
| 178 | Description: cfg.Description, |
| 179 | Metadata: cfg.Metadata, |
| 180 | } |
| 181 | |
| 182 | return nil |
| 183 | } |
| 184 | |
| 185 | // Get retrieves an agent by ID. |
| 186 | func (r *Registry) Get(id string) (agent.Agent, error) { |
no test coverage detected