The Upstreet Agents SDK is now in public beta 🎉 Get started →
API ReferenceComponents

<PerceptionModifier>

Intercept and modify agent perception handling.

The PerceptionModifier component is used to modify and enhance perception handling within the agent's context. It acts as a middleware layer for perception events, allowing you to transform, filter, or augment incoming perceptions.

Import

import { PerceptionModifier } from 'react-agents';

Usage

Here's an example of how to use the PerceptionModifier component:

import { PerceptionModifier, Perception } from 'react-agents';
 
function MyComponent() {
  return (
    <PerceptionModifier
      before={(perception) => {
        // Modify perception before processing
        console.log('Intercepting perception:', perception);
        return {
          ...perception,
          timestamp: Date.now()
        };
      }}
      after={(result) => {
        // Handle the result after perception processing
        console.log('Perception handled:', result);
        return result;
      }}
    >
      <Perception
        type="visual"
        handler={(data) => {
          // Handle perception data
        }}
      />
    </PerceptionModifier>
  );
}

Props

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

Best Practices

Efficient Processing

  • Keep modification logic lightweight
  • Use async functions for heavy processing
  • Implement proper error handling

Proper Chaining

  • Multiple modifiers can be chained
  • Consider the order of modifications
  • Return modified data in the correct format

On this page

Facing an issue? Add a ticket.