import { getOpenAIModel } from "./openai-provider-CqpHDwSr.js";
import { Output, generateText } from "ai";

//#region src/internal/agents/callEmbeddedAgent.ts
/**
* Call an embedded agent with tool call capture
* This is the standard way to call embedded AI agents within MCP tools
*
* Error handling:
* - Errors are re-thrown for the calling agent to handle
* - Each agent can implement its own error handling strategy
*/
async function callEmbeddedAgent({ system, prompt, tools, schema }) {
	const capturedToolCalls = [];
	const result = await generateText({
		model: getOpenAIModel(),
		system,
		prompt,
		tools,
		maxSteps: 5,
		temperature: 1,
		experimental_output: Output.object({ schema }),
		onStepFinish: (event) => {
			if (event.toolCalls && event.toolCalls.length > 0) for (const toolCall of event.toolCalls) capturedToolCalls.push({
				toolName: toolCall.toolName,
				args: toolCall.args
			});
		}
	});
	if (!result.experimental_output) throw new Error("Failed to generate output");
	return {
		result: result.experimental_output,
		toolCalls: capturedToolCalls
	};
}

//#endregion
export { callEmbeddedAgent };
//# sourceMappingURL=callEmbeddedAgent-BSnzLPfW.js.map