Skip to content

Feature request: Add Pi framework integration #151

@gaocegege

Description

@gaocegege

Summary

Requesting a createPiTool(executor) integration for the Pi agent toolkit (@mariozechner/pi-agent-core), following the same pattern as the existing Vercel AI SDK integration.

Motivation

Pi is a popular TypeScript AI agent toolkit (43k+ GitHub stars) by Mario Zechner. It provides a layered architecture (pi-aipi-agent-corepi-coding-agent) with a clean tool interface using TypeBox schemas. Currently, agent-diff has only one TypeScript integration (Vercel AI SDK) — adding Pi would expand coverage to a second major TS agent framework.

Proposed API

Following the established pattern (createVercelAITool, create_langchain_tool, create_openai_tool):

import { AgentDiff, TypeScriptExecutorProxy, createPiTool } from 'agent-diff';
import { Agent } from '@mariozechner/pi-agent-core';
import { getModel, streamSimple } from '@mariozechner/pi-ai';

const client = new AgentDiff();
const env = await client.initEnv({
  templateService: 'slack',
  templateName: 'slack_default',
  impersonateUserId: 'U01AGENBOT9',
});

const executor = new TypeScriptExecutorProxy(env.environmentId, client.getBaseUrl());
const tool = await createPiTool(executor);

const agent = new Agent({
  initialState: {
    systemPrompt: 'You are a helpful assistant.',
    model: getModel('anthropic', 'claude-sonnet-4-6'),
    tools: [tool],
  },
  streamFn: streamSimple,
});

const run = await client.startRun({ envId: env.environmentId });
await agent.prompt('Post "Hello World!" to Slack channel C01GENERAL99.');
const diff = await client.diffRun({ runId: run.runId });

Implementation notes

Pi tools use the AgentTool<T> interface with TypeBox parameter schemas:

import { Type } from '@mariozechner/pi-ai';
import type { AgentTool } from '@mariozechner/pi-agent-core';

const params = Type.Object({
  code: Type.String({ description: 'TypeScript code to execute' }),
});

const tool: AgentTool<typeof params> = {
  name: 'execute_typescript',
  label: 'Execute Code',
  description: '...',
  parameters: params,
  execute: async (toolCallId, params, signal, onUpdate) => {
    const result = await executor.execute(params.code);
    return {
      content: [{ type: 'text', text: result }],
      details: {},
    };
  },
};

The mapping from agent-diff's executor to Pi's AgentTool is straightforward — similar in shape to the Vercel AI tool wrapper.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions