MCPcopy Create free account
hub / github.com/anomalyco/opencode-bench / run

Function run

src/agents/codex.ts:71–113  ·  view source on GitHub ↗
(model, prompt, options)

Source from the content-addressed store, hash-verified

69
70const codexAgent: Agent.Definition<(typeof models)[number]> = {
71 async run(model, prompt, options) {
72 options.logger.log(
73 `codex-sdk --model ${model} --sandbox ${DEFAULT_SANDBOX} ${prompt}`,
74 );
75
76 const key = sessionKey(model, options.cwd);
77 const thread = getOrCreateThread(model, options.cwd);
78
79 const actions: string[] = [];
80 let usage: Usage;
81 let cost = 0;
82 try {
83 const pricingKey = model;
84 const pricing = openai.models[pricingKey]?.cost;
85 const turn = await thread.run(prompt);
86 assert(turn.usage, "The agent did not emit the usage information.");
87 usage = turn.usage;
88 const billableInput =
89 (usage.input_tokens ?? 0) - (usage.cached_input_tokens ?? 0);
90 const cachedInput = usage.cached_input_tokens ?? 0;
91 const output = usage.output_tokens ?? 0;
92 cost =
93 (billableInput * pricing.input +
94 output * pricing.output +
95 cachedInput * pricing.cache_read) /
96 1_000_000;
97
98 actions.push(...turn.items.map((item) => JSON.stringify(item)));
99 logTurnItems(turn.items, options);
100 } catch (error) {
101 threadCache.delete(key);
102 throw error;
103 }
104
105 return {
106 actions,
107 usage: {
108 input: usage.input_tokens,
109 output: usage.output_tokens,
110 cost,
111 },
112 };
113 },
114};
115
116export default codexAgent;

Callers

nothing calls this directly

Calls 3

getOrCreateThreadFunction · 0.85
logTurnItemsFunction · 0.85
sessionKeyFunction · 0.70

Tested by

no test coverage detected