npm.io
0.24.0 • Published 2d ago

@moxxy/agent

Licence
MIT
Version
0.24.0
Deps
5
Size
20 kB
Vulns
0
Weekly
1.4K

@moxxy/agent

The fastest way to run a moxxy agent — one install, one call. Batteries included: it bundles the runtime (@moxxy/core), the default loop, and the OpenAI + Anthropic providers behind drop-in presets.

npm i @moxxy/agent

Hello, agent

import { setupAgent, openaiPreset } from '@moxxy/agent';

const { ask } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));

console.log(await ask('Write a haiku about TypeScript.'));

Stream the events instead:

const { stream } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));

for await (const event of stream('Explain async generators.')) {
  if (event.type === 'assistant_chunk') process.stdout.write(event.delta);
}

Claude, or both

import { setupAgent, openaiPreset, anthropicPreset } from '@moxxy/agent';

// Just Claude:
const claude = setupAgent(anthropicPreset({ apiKey: process.env.ANTHROPIC_API_KEY }));

// Or register both and switch per turn (the first preset is active):
const agent = setupAgent([
  openaiPreset({ apiKey: process.env.OPENAI_API_KEY }),
  anthropicPreset({ apiKey: process.env.ANTHROPIC_API_KEY }),
]);
await agent.ask('Hi from OpenAI');
agent.setProvider('anthropic');
await agent.ask('Now from Claude');

Add tools, swap blocks live

import { setupAgent, openaiPreset } from '@moxxy/agent';
import { defineTool } from '@moxxy/sdk';
import { z } from 'zod';

const agent = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));

agent.addTool(
  defineTool({
    name: 'get_weather',
    description: 'Current weather for a city.',
    inputSchema: z.object({ city: z.string() }),
    handler: async ({ city }) => `Sunny in ${city}.`,
  }),
);

console.log(await agent.ask("What's the weather in Paris?"));

agent.session is the live moxxy Session — full control for anything the sugar doesn't cover.

Presets

preset options
openaiPreset(opts?) apiKey (→ OPENAI_API_KEY), model, baseURL (OpenAI-compatible vendors: z.ai/xAI/Google/Ollama)
anthropicPreset(opts?) apiKey (→ ANTHROPIC_API_KEY), model

Need more control or a different provider/mode? Drop down to @moxxy/core's setupAgent({ plugins, provider, tools, … }) and register any blocks you like — @moxxy/agent re-exports setupAgent and all its types.

License

MIT

Keywords