# Execute Agent — Serenity* AI Hub

> Executes an agent by its code with the provided parameters. See the documentation

- Key: `serenity_ai_hub-execute-agent`
- Type: Action (Write)
- Version: 0.0.1
- App: Serenity* AI Hub (`serenity_ai_hub`) — https://pipedream.com/apps/serenity-ai-hub.md
- This page (HTML): https://pipedream.com/apps/serenity-ai-hub/actions/execute-agent
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/serenity_ai_hub/actions/execute-agent/execute-agent.mjs

## Description

Executes an agent by its code with the provided parameters. [See the documentation](https://docs.serenitystar.ai/docs/api/aihub/execute-agent-with-code/)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `agentCode` | `string` | Yes | The unique identifier code of the agent Options are loaded from the connected account. |
| `message` | `string` | Yes | The message to send to the agent |
| `culture` | `string` | No | Overrides the response language |
| `chatId` | `string` | No | The ID of an existing conversation to continue. Leave empty to start a new conversation |
| `additionalParameters` | `string[]` | No | Array of additional parameters with key and value properties, or a JSON string representing that array. Example: [{"key": "param1", "value": "value1"}] |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "serenity_ai_hub",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "serenity_ai_hub-execute-agent",
  arguments: {
    agentCode: "Agent Code",
    message: "Message",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "serenity_ai_hub-execute-agent",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    serenity_ai_hub: { authProvisionId: "apn_xxxxxxx" },
    agentCode: "Agent Code",
    message: "Message",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "serenity_ai_hub-execute-agent",
    "configured_props": {
      "serenity_ai_hub": { "authProvisionId": "apn_xxxxxxx" },
      "agentCode": "Agent Code",
      "message": "Message"
    }
  }'
```

---

- App: https://pipedream.com/apps/serenity-ai-hub.md · All apps: https://pipedream.com/apps
