(
id: string,
homedir: string,
type: AgentType,
config: Partial<AgentOptions> = {},
parentAgentId: string | null = null,
)
| 793 | } |
| 794 | |
| 795 | private instantiateAgent( |
| 796 | id: string, |
| 797 | homedir: string, |
| 798 | type: AgentType, |
| 799 | config: Partial<AgentOptions> = {}, |
| 800 | parentAgentId: string | null = null, |
| 801 | ): Agent { |
| 802 | const parentAgent = parentAgentId !== null ? this.getReadyAgent(parentAgentId) : undefined; |
| 803 | const cwd = parentAgent?.config.cwd ?? this.toolKaos.getcwd(); |
| 804 | let agent!: Agent; |
| 805 | agent = new Agent({ |
| 806 | ...config, |
| 807 | type, |
| 808 | kaos: this.toolKaos.withCwd(cwd), |
| 809 | toolServices: this.options.toolServices, |
| 810 | config: this.options.config, |
| 811 | homedir, |
| 812 | // Session-level, shared across agents: originals persisted for |
| 813 | // compression captions live with the session, not the agent. |
| 814 | mediaOriginalsDir: sessionMediaOriginalsDir(this.options.homedir), |
| 815 | skills: this.skills, |
| 816 | rpc: proxyWithExtraPayload(this.rpc, { agentId: id }), |
| 817 | modelProvider: this.options.providerManager, |
| 818 | hookEngine: config.hookEngine ?? this.hookEngine, |
| 819 | subagentHost: config.subagentHost ?? new SessionSubagentHost(this, id), |
| 820 | mcp: this.mcp, |
| 821 | permission: this.permissionOptions(parentAgentId, config.permission), |
| 822 | telemetry: this.telemetry, |
| 823 | log: this.log.createChild({ agentId: id }), |
| 824 | pluginSessionStarts: type === 'main' ? this.options.pluginSessionStarts : undefined, |
| 825 | pluginCommands: type === 'main' ? this.options.pluginCommands : undefined, |
| 826 | experimentalFlags: this.experimentalFlags, |
| 827 | additionalDirs: parentAgent?.getAdditionalDirs() ?? this.additionalDirs, |
| 828 | systemPromptContextProvider: () => |
| 829 | prepareSystemPromptContext( |
| 830 | this.systemContextKaos(agent.kaos.getcwd()), |
| 831 | this.options.kimiHomeDir, |
| 832 | { additionalDirs: agent.getAdditionalDirs() }, |
| 833 | ), |
| 834 | }); |
| 835 | return agent; |
| 836 | } |
| 837 | |
| 838 | private permissionOptions( |
| 839 | parentAgentId: string | null, |
no test coverage detected