Effect CommunityEC
Effect Community5mo ago
19 replies
Afonso Matos

Clarification on Vercel AI SDK and Effect Toolkit Integration

I'm kinda confused here, so Vercel AI SDK seems to have a little LLM loop inside their generateText/Object, so the framework itself will call the tools and feed them into the LLM to generate the final result.

Effect AI doesn't do this right?
Here's an example:

import { AiLanguageModel, AiTool, AiToolkit } from "@effect/ai/index";
import { NodeRuntime } from "@effect/platform-node/index";
import { Effect, Schema } from "effect/index";
import { Gemini_2_5_Flash_Lite } from "~/lib/services/ai";

class ChatTools extends AiToolkit.make(
    AiTool.make("GetAge", {
        description: `Provide the age of any person`,
        success: Schema.Number,
        failure: Schema.Never,
        parameters: {
            name: Schema.String
        }
    })
) {}

const ChatToolsLive = ChatTools.toLayer(
    Effect.gen(function* () {
        return {
            GetAge: ({ name }) => {
                if (name === "John") {
                    return Effect.succeed(20);
                }
                return Effect.succeed(30);
            }
        };
    })
);

NodeRuntime.runMain(
    Effect.gen(function* () {
        const model = yield* AiLanguageModel.AiLanguageModel;
        const answer = yield* model.generateText({
            prompt: "How old is John?",
            toolkit: ChatTools
        });
        console.log(answer.text);
    }).pipe(Effect.provide([ChatToolsLive, Gemini_2_5_Flash_Lite]))
);
Was this page helpful?