Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@loopstack/accessing-tool-results-example-workflow

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loopstack/accessing-tool-results-example-workflow

A simple workflow showing different methods of how to access tool results in a subsequent workflow step.

latest
npmnpm
Version
0.23.0
Version published
Weekly downloads
71
-67.43%
Maintainers
1
Weekly downloads
 
Created
Source

@loopstack/accessing-tool-results-example-workflow

A module for the Loopstack AI automation framework.

This module provides an example workflow demonstrating how to store and access data across workflow transitions using typed workflow state.

Overview

The workflow shows how to persist data between transitions by returning updated state from transition methods. Understanding this pattern is essential for building workflows that pass data between steps. For example, storing tool results in one transition and reading them in the next.

By using this workflow as a reference, you'll learn how to:

  • Define a typed state interface for your workflow
  • Store data in the initial transition and return updated state
  • Access stored data in later transitions via the state parameter
  • Save chat messages with MessageDocument and DocumentStore

This example is useful for developers learning to build data-driven workflows that need to pass information between steps.

Installation

See SETUP.md for installation and setup instructions.

How It Works

Workflow State

State is defined as a TypeScript interface and passed to each transition method. Return the updated state from a transition to persist it for subsequent steps:

interface ToolResultsState {
  storedMessage?: string;
}

@Workflow({
  uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
})
export class WorkflowToolResultsWorkflow extends BaseWorkflow<Record<string, unknown>, ToolResultsState> {
  constructor(@Inject(DOCUMENT_STORE) private readonly documentStore: DocumentStore) {
    super();
  }
}

Key Concepts

1. Storing Data in State

In the initial transition, save a message document and return updated state:

@Transition({ to: 'data_created' })
async createSomeData(
  ctx: WorkflowContext,
  args: Record<string, unknown>,
  state: ToolResultsState,
): Promise<ToolResultsState> {
  await this.documentStore.save(MessageDocument, {
    role: 'assistant',
    content: `Stored in initial transition: Hello World.`,
  });
  return { ...state, storedMessage: 'Hello World.' };
}

The returned state is persisted automatically and available in later transitions.

2. Accessing Data Across Transitions

In a subsequent transition, read values from the state parameter:

@Transition({ from: 'data_created', to: 'end' })
async accessData(ctx: WorkflowContext, state: ToolResultsState): Promise<unknown> {
  await this.documentStore.save(MessageDocument, {
    role: 'assistant',
    content: `Accessed from previous transition: ${state.storedMessage}`,
  });
  return {};
}

Complete Workflow

import { Inject } from '@nestjs/common';
import { BaseWorkflow, DOCUMENT_STORE, Final, Initial, MessageDocument, Workflow } from '@loopstack/common';
import type { DocumentStore, WorkflowContext } from '@loopstack/common';

interface ToolResultsState {
  storedMessage?: string;
}

@Workflow({
  uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
})
export class WorkflowToolResultsWorkflow extends BaseWorkflow<Record<string, unknown>, ToolResultsState> {
  constructor(@Inject(DOCUMENT_STORE) private readonly documentStore: DocumentStore) {
    super();
  }

  @Transition({ to: 'data_created' })
  async createSomeData(
    ctx: WorkflowContext,
    args: Record<string, unknown>,
    state: ToolResultsState,
  ): Promise<ToolResultsState> {
    await this.documentStore.save(MessageDocument, {
      role: 'assistant',
      content: `Stored in initial transition: Hello World.`,
    });
    return { ...state, storedMessage: 'Hello World.' };
  }

  @Transition({ from: 'data_created', to: 'end' })
  async accessData(ctx: WorkflowContext, state: ToolResultsState): Promise<unknown> {
    await this.documentStore.save(MessageDocument, {
      role: 'assistant',
      content: `Accessed from previous transition: ${state.storedMessage}`,
    });
    return {};
  }
}

Dependencies

This workflow uses the following Loopstack modules:

  • @loopstack/common — Base classes, decorators, DocumentStore, and MessageDocument

About

Author: Jakob Klippel

License: MIT

Additional Resources

Keywords

assign

FAQs

Package last updated on 03 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts