getHostExports
getHostExports(
ctx):HostExports
Defined in: index.ts:346
Get host llmist exports from execution context.
External gadgets MUST use this instead of importing classes directly from ‘llmist’ to ensure they use the same version as the host CLI, enabling proper tree sharing and avoiding the “dual-package problem”.
Parameters
Section titled “Parameters”The execution context passed to gadget.execute()
Returns
Section titled “Returns”The host’s llmist exports (AgentBuilder, Gadget, etc.)
Throws
Section titled “Throws”Error if ctx or ctx.hostExports is undefined
Example
Section titled “Example”import { getHostExports, Gadget, z } from 'llmist';import type { ExecutionContext } from 'llmist';
class BrowseWeb extends Gadget({ name: 'BrowseWeb', description: 'Browse a website autonomously', schema: z.object({ task: z.string(), url: z.string() }),}) { async execute(params: this['params'], ctx?: ExecutionContext) { // Get host's AgentBuilder to ensure tree sharing works correctly const { AgentBuilder } = getHostExports(ctx!);
const agent = new AgentBuilder() .withParentContext(ctx!) .withGadgets(Navigate, Click, Screenshot) .ask(params.task);
for await (const event of agent.run()) { // Events flow through host's shared tree } }}