Skip to content

agent

The @philschmid/agent package provides a batteries-included layer on top of agents-core. It’s designed for building production agents quickly.

  • Hooks: Intercept and control agent lifecycle events (beforeToolExecute, afterToolExecute, etc.)
  • Built-in tools: Ready-to-use tools for file operations, shell commands, and web access
  • Skills: Load specialized capabilities from YAML+Markdown files
  • Subagents: Delegate tasks to specialized agents

For lower-level control, see the @philschmid/agents-core package.


Terminal window
bun add @philschmid/agent
Terminal window
export GEMINI_API_KEY="your-api-key"

The main entry point is createAgentSession, which wraps the core Session with hooks and tool resolution:

import { createAgentSession } from '@philschmid/agent';
const session = createAgentSession({
model: 'gemini-3-flash-preview',
tools: ['read', 'write', 'bash'],
systemInstruction: 'You are a coding assistant.',
});
session.send('List files in the current directory');
for await (const event of session.stream()) {
if (event.type === 'text.delta') process.stdout.write(event.delta);
}

Pass tool names as strings, the session resolves them to full tool implementations automatically.


Reference tools by string name:

NameTool(s)Description
readread_file, list_directoryRead files and list directories
writewrite_file, apply_patchCreate/overwrite files & patch existing
bashbashExecute shell commands
grepgrepSearch in files
web_searchweb_searchSearch the web
web_fetchweb_fetchFetch URL content
sleepsleepPause execution
planupdate_planUpdate agent planning state
skillsskillsLoad and invoke skills
subagentsubagentDelegate to a subagent

Control agent behavior by intercepting lifecycle events:

// Log all tool calls
session.on('beforeToolExecute', (event) => {
console.log(`[TOOL] ${event.toolName}`);
return { allow: true };
});
// Block destructive commands
session.on('beforeToolExecute', (event) => {
if (event.toolName === 'bash') {
const cmd = event.arguments.command as string;
if (cmd.includes('rm -rf')) {
return { allow: false, reason: 'Blocked destructive command' };
}
}
return { allow: true };
});

Hooks can allow, block, or modify tool calls before execution. See Hooks for all available lifecycle events.