The @palico-ai/client-js is a Javascript library that helps you communicate with your Palico application. This library should primarily be used in secured server-side environments, such as a NodeJS server or a NextJS server runtime.

Setup and Installation

To install the Palico Client SDK on your NodeJS project, run the following command:

npm install @palico-ai/client-js

Create a Palico Client

1

Generate a Service Key

You can generate a service key from your Palico App project directory

npm run palico generate apikey
2

Create a Palico Client

import { createClient } from "@palico-ai/client-js";

const client = createClient({
  serviceKey: "<your-service-key>",
  apiURL: "http://localhost:8000", // replace with your API URL
});

Calling an Agent

Here’s an example of how you can call an agent using the Palico Client SDK:

const response = await client.agent.chat({
  agentName: "chat",
  userMessage: "What is the weather today?",
  payload: {
    location: "San Francisco",
  },
  appConfig: {
    model: "gpt-3.5-turbo",
    provider: "openai",
  },
});

const { conversationId, requestId, message, data, toolCalls } = response;

Learn about the API reference for the chat method here.

Stream Response

You can also stream the response from the agent. Here’s an example of how you can stream the response from the agent:

  const response = await client.agent.chat({
    agentName: "chat_stream",
    userMessage: "Hello",
    appConfig: {},
    stream: true,
  });

for await (const chunk of response.readChunks()) {
  // Do something with the chunk
}

You can also get the merged chunks from the stream during or after the stream has completed:

const mergedChunks = await response.getMergedChunks();

API Reference

chat()

Input

The chat method accepts the following parameters:

agentName
string
required

The name of the agent you want to call. This should match the agent folder name.

userMessage
string
required

Message to send to the agent.

payload
json

Additional data to send to the agent.

appConfig
json

App Config value to send to your agent. Learn more about App Config.

stream
boolean

Should the response be streamed back to the client

toolCallResults
ToolCallResult[]

For client-side tool execution, the results of the tool call. The schema for a ToolCallResult is as follows:

interface ToolCallResult {
  name: string;
  result: any;
}

Output (Non-Streaming)

The chat method returns a promise that resolves to a ChatResponse object:

conversationId
string
required

Unique identifier for the conversation.

requestId
string
required

Unique identifier for the request.

message
string

The message to be sent back to the user.

data
json

Additional data to be sent back to the user.

toolCalls
ToolCall[]

If the agent requires a client-side tool execution, this field will contain the tool name and parameters. The schema for a ToolCall is as follows:

interface ToolCall {
  id: string;
  name: string;
  parameters?: JSON;
}