The Upstreet Agents SDK is now in public beta 🎉 Get started →
bg-pattern
📚 API ReferenceComponents

<ActionModifier>

Intercept and modify agent action handling.

The ActionModifier enables middleware-like modification of actions within your agent system, allowing for pre and post-processing of actions. The ActionModifier component serves as a wrapper that intercepts and modifies actions before and after execution.

Import

import { ActionModifier } from 'react-agents';

Usage

Here's a basic example of using the ActionModifier:

 
import { ActionModifier, Action } from 'react-agents';
 
function MyComponent() {
  return (
    <ActionModifier
      before={(action) => {
        // Pre-process action
        console.log('Before action:', action);
        return action;
      }}
      after={(result) => {
        // Post-process result
        console.log('After action:', result);
        return result;
      }}
    >
      <Action name="exampleAction" handler={() => {}} />
    </ActionModifier>
  );
}

Props

PropTypeDefault
before
Function(action) => action
N/A
after
Function(result) => result
N/A

Best Practices

  • Keep modifiers focused on specific concerns
  • Chain multiple modifiers for complex modifications
  • Handle errors appropriately in before/after handlers
  • Avoid heavy computations that might block the main thread
  • Return the modified action/result from handlers

On this page

Facing an issue? Add a ticket.