npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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

v0.23.3

Published

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

Readme


title: Accessing Tool Results Example description: Example workflow showing how to store and access data across workflow transitions using typed workflow state

@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

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

Then register the module in your app:

import {
  ToolResultsExampleModule,
  WorkflowToolResultsWorkflow,
} from '@loopstack/accessing-tool-results-example-workflow';
import { StudioApp } from '@loopstack/common';

@StudioApp({
  title: 'Tool Results Example',
  workflows: [WorkflowToolResultsWorkflow],
})
@Module({
  imports: [ToolResultsExampleModule],
})
export class MyAppModule {}

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',
    text: `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',
    text: `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',
      text: `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',
      text: `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