> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# expression

> Add a pattern-based response without an API call.

[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**

**`test_value`** `str` — required

Template string to test (e.g., `"${args.command}"`).

---

**`pattern`** `str | re.Pattern` — required

Regex pattern to match against the test value.

---

**`output`** `FunctionResult` — required

[FunctionResult][ref-functionresult] to return when the pattern matches.

---

**`nomatch_output`** `FunctionResult`

Optional FunctionResult to return when the pattern does not match.

---

## **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()
```