***

title: expression
slug: /reference/python/agents/data-map/expression
description: Add a pattern-based response without an API call.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ref-datamap]: /docs/server-sdks/reference/python/agents/data-map

[ref-functionresult]: /docs/server-sdks/reference/python/agents/function-result

Add a pattern-based response that does not require an API call. Expressions are
evaluated in order; the first matching pattern wins.

## **Parameters**

<ParamField path="test_value" type="str" required={true} toc={true}>
  Template string to test (e.g., `"${args.command}"`).
</ParamField>

<ParamField path="pattern" type="str | re.Pattern" required={true} toc={true}>
  Regex pattern to match against the test value.
</ParamField>

<ParamField path="output" type="FunctionResult" required={true} toc={true}>
  [FunctionResult][ref-functionresult] to return when the pattern matches.
</ParamField>

<ParamField path="nomatch_output" type="FunctionResult" toc={true}>
  Optional FunctionResult to return when the pattern does not match.
</ParamField>

## **Returns**

[`DataMap`][ref-datamap] -- Self for method chaining.

## **Example**

```python {8,12,16}
from signalwire import AgentBase, DataMap
from signalwire import FunctionResult

volume_control = (
    DataMap("set_volume")
    .purpose("Control audio volume")
    .parameter("level", "string", "Volume level", required=True)
    .expression(
        "${args.level}", r"high|loud|up",
        FunctionResult("Volume increased")
    )
    .expression(
        "${args.level}", r"low|quiet|down",
        FunctionResult("Volume decreased")
    )
    .expression(
        "${args.level}", r"mute|off",
        FunctionResult("Audio muted")
    )
)

agent = AgentBase(name="media-agent")
agent.set_prompt_text("You are a helpful assistant.")
agent.register_swaig_function(volume_control.to_swaig_function())

if __name__ == "__main__":
    agent.run()
```