Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { lettaAuth } from '../common/auth';
import { getLettaClient } from '../common/client';
import { agentIdDropdown } from '../common/props';
import type {
  MessageCreateParamsNonStreaming,
  LettaResponse,
} from '../common/types';

export const sendMessageToAgent = createAction({
  auth: lettaAuth,
  name: 'sendMessageToAgent',
  classification: 'WRITE',
  displayName: 'Send Message to Agent',
  description: 'Send message to an agent',
  audience: 'both',
  aiMetadata: { description: 'Sends a message to a specific Letta agent (by agent ID) and returns the agent\'s non-streaming response, optionally capping how many reasoning steps it may take. Use to converse with or prompt an existing agent. Not idempotent: each call appends a new message and advances the agent\'s stateful memory.', idempotent: false },
  props: {
    agentId: agentIdDropdown,
    input: Property.LongText({
      displayName: 'Message',
      description: 'The message content to send to the agent',
      required: true,
    }),
    maxSteps: Property.Number({
      displayName: 'Max Steps',
      description: 'Maximum number of steps the agent should take to process the request',
      required: false,
    }),
  },
  async run(context) {
    const {
      agentId,
      input,
      maxSteps,
    } = context.propsValue;

    const client = getLettaClient(context.auth.props);

    const body: MessageCreateParamsNonStreaming = {
      streaming: false,
      input: input,
    };

    if (maxSteps !== undefined && maxSteps !== null) {
      body.max_steps = maxSteps;
    }

    const response: LettaResponse = await client.agents.messages.create(
      agentId,
      body
    );

    return {
      messages: response.messages,
      stopReason: response.stop_reason,
      success: true,
    };
  },
});