# Workflows API
[EN] Source: https://mastra.ai/reference/client-js/workflows

The Workflows API provides methods to interact with and execute automated workflows in Mastra.

## Getting All Workflows

Retrieve a list of all available workflows:

```typescript
const workflows = await mastraClient.listWorkflows();
```

## Working with a Specific Workflow

Get an instance of a specific workflow as defined by the const name:

```typescript title="src/mastra/workflows/test-workflow.ts"
export const testWorkflow = createWorkflow({
  id: "city-workflow",
});
```

```typescript
const workflow = mastraClient.getWorkflow("testWorkflow");
```

## Workflow Methods

### Get Workflow Details

Retrieve detailed information about a workflow:

```typescript
const details = await workflow.details();
```

### Start workflow run asynchronously

Start a workflow run with inputData and await full run results:

```typescript
const run = await workflow.createRunAsync();

const result = await run.startAsync({
  inputData: {
    city: "New York",
  },
});
```

### Resume Workflow run asynchronously

Resume a suspended workflow step and await full run result:

```typescript
const run = await workflow.createRunAsync();

const result = await run.resumeAsync({
  step: "step-id",
  resumeData: { key: "value" },
});
```

### Watch Workflow

Watch workflow transitions:

```typescript
try {
  const workflow = mastraClient.getWorkflow("testWorkflow");

  const run = await workflow.createRunAsync();

  run.watch((record) => {
    console.log(record);
  });

  const result = await run.start({
    inputData: {
      city: "New York",
    },
  });
} catch (e) {
  console.error(e);
}
```

### Resume Workflow

Resume workflow run and watch workflow step transitions:

```typescript
try {
  const workflow = mastraClient.getWorkflow("testWorkflow");

  const run = await workflow.createRunAsync({ runId: prevRunId });

  run.watch((record) => {
    console.log(record);
  });

  run.resume({
    step: "step-id",
    resumeData: { key: "value" },
  });
} catch (e) {
  console.error(e);
}
```

### Stream Workflow

Stream workflow execution for real-time updates:

```typescript
try {
  const workflow = mastraClient.getWorkflow("testWorkflow");

  const run = await workflow.createRunAsync();

  const stream = await run.stream({
    inputData: {
      city: "New York",
    },
  });

  for await (const chunk of stream) {
    console.log(JSON.stringify(chunk, null, 2));
  }
} catch (e) {
  console.error("Workflow error:", e);
}
```

### Get Workflow Run result

Get the result of a workflow run:

```typescript
try {
  const workflow = mastraClient.getWorkflow("testWorkflow");

  const run = await workflow.createRunAsync();

  // start the workflow run
  const startResult = await run.start({
    inputData: {
      city: "New York",
    },
  });

  const result = await workflow.runExecutionResult(run.runId);

  console.log(result);
} catch (e) {
  console.error(e);
}
```

This is useful when dealing with long running workflows. You can use this to poll the result of the workflow run.

### Workflow run result

A workflow run result yields the following:

| Field            | Type                                                                                                                                                                                                                                               | Description                                      |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| `payload`        | `{currentStep?: {id: string, status: string, output?: Record<string, any>, payload?: Record<string, any>}, workflowState: {status: string, steps: Record<string, {status: string, output?: Record<string, any>, payload?: Record<string, any>}>}}` | The current step and workflow state of the run   |
| `eventTimestamp` | `Date`                                                                                                                                                                                                                                             | The timestamp of the event                       |
| `runId`          | `string`                                                                                                                                                                                                                                           | Unique identifier for this workflow run instance |


---
title: "Reference: Mastra.getAgent() | Core"
description: "Documentation for the `Agent.getAgent()` method in Mastra, which retrieves an agent by name."
---