| 499 | } |
| 500 | |
| 501 | async createAgent( |
| 502 | config: Partial<AgentOptions>, |
| 503 | options: CreateAgentOptions = {}, |
| 504 | ): Promise<{ readonly id: string; readonly agent: Agent }> { |
| 505 | await this.skillsReady; |
| 506 | const type = config.type ?? 'main'; |
| 507 | const id = type === 'main' ? 'main' : this.nextGeneratedAgentId(); |
| 508 | const homedir = config.homedir ?? join(this.options.homedir, 'agents', id); |
| 509 | const parentAgentId = options.parentAgentId ?? null; |
| 510 | const agent = this.instantiateAgent(id, homedir, type, config, parentAgentId); |
| 511 | if (options.profile) { |
| 512 | await this.bootstrapAgentProfile(agent, options.profile); |
| 513 | } |
| 514 | |
| 515 | this.agents.set(id, agent); |
| 516 | if (options.persistMetadata !== false) { |
| 517 | this.metadata.agents[id] = { |
| 518 | homedir, |
| 519 | type, |
| 520 | parentAgentId, |
| 521 | swarmItem: options.swarmItem, |
| 522 | }; |
| 523 | void this.writeMetadata(); |
| 524 | } |
| 525 | |
| 526 | return { id, agent }; |
| 527 | } |
| 528 | |
| 529 | async ensureAgentResumed(id: string): Promise<Agent> { |
| 530 | const entry = this.agents.get(id); |