MCPcopy Create free account
hub / github.com/QuantiaAI/helm-agents / createEngine

Function createEngine

packages/core/src/engine.ts:57–148  ·  view source on GitHub ↗
(
  config: ResolvedConfig,
  overrides: EngineOverrides = {},
)

Source from the content-addressed store, hash-verified

55}
56
57export function createEngine(
58 config: ResolvedConfig,
59 overrides: EngineOverrides = {},
60): Engine {
61 const llmOpts = {
62 provider: config.llmProvider,
63 baseUrl: config.backendUrl ?? undefined,
64 };
65 const quick =
66 overrides.quick ??
67 createLlmClient({ ...llmOpts, model: config.quickThinkLlm });
68 const deep =
69 overrides.deep ??
70 createLlmClient({ ...llmOpts, model: config.deepThinkLlm });
71 const route = createRouter(
72 config,
73 buildVendorRegistry(overrides.fetchImpl),
74 );
75 const deps: AgentDeps = { quick, deep, route, config };
76
77 const compile = (selected?: AnalystKey[], outputLanguage?: string) => {
78 const runDeps =
79 outputLanguage && outputLanguage !== config.outputLanguage
80 ? { ...deps, config: { ...deps.config, outputLanguage } }
81 : deps;
82 return buildGraph(runDeps, { selectedAnalysts: selected ?? DEFAULT_ANALYSTS });
83 };
84
85 const makeState = (input: AnalyzeInput): AgentState =>
86 createInitialState({
87 ticker: input.ticker,
88 tradeDate: input.tradeDate,
89 assetType: input.assetType ?? detectAssetType(input.ticker),
90 instrumentContext: input.instrumentContext,
91 pastContext: input.pastContext,
92 });
93
94 return {
95 async propagate(input) {
96 const graph = compile(input.selectedAnalysts, input.outputLanguage);
97 const finalState = (await graph.invoke(makeState(input), {
98 recursionLimit: config.maxRecurLimit,
99 })) as AgentState;
100 const rating = processSignal(finalState.finalTradeDecision);
101 return { finalState, rating };
102 },
103
104 async reflect(prompt: string): Promise<string> {
105 const res = await deep.invoke({ messages: [{ role: "user", content: prompt }] });
106 return res.content;
107 },
108
109 async *streamEvents(input, signal): AsyncIterable<RunEvent> {
110 const graph = compile(input.selectedAnalysts, input.outputLanguage);
111 const accumulated = makeState(input);
112 try {
113 const stream = await graph.stream(accumulated, {
114 recursionLimit: config.maxRecurLimit,

Callers 2

getForUserMethod · 0.90
engine.test.tsFile · 0.85

Calls 3

createLlmClientFunction · 0.90
createRouterFunction · 0.90
buildVendorRegistryFunction · 0.90

Tested by

no test coverage detected