> For the complete documentation index, see [llms.txt](https://docs.algenta.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.algenta.ai/sdks/python/simulations-and-queries.md).

# Simulations & queries

Python SDK reference for the simulation and query methods — simulate, resolve, query, query\_batch, verify, recommend, score, compare, and plan\_decision.

These methods run Monte Carlo simulations and governed queries against the Algenta engine. They are available on both `AlgentaClient` and `AsyncAlgentaClient` (await the async calls). Simulation and recommendation methods take keyword arguments; the query methods take a request dict and, where noted, merge extra keyword arguments into the body. See [API overview](/http-api/overview.md) for the underlying HTTP contract and [Simulation models](/concepts/simulation-models.md) for the distributions.

## Method reference

| Method                                        | Purpose                                                                                                                            |
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `simulate(**kwargs)`                          | Run a Monte Carlo simulation and return a `DecisionEnvelope`. Posts to `/v1/simulate`.                                             |
| `resolve(request=None, **kwargs)`             | Resolve a partial or natural-language hint into a typed, executable plan (`ResolveResult`). Posts to `/v1/resolve`.                |
| `query(request=None, **kwargs)`               | Run a governed exact query and return matching rows (`QueryResult`). Posts to `/v1/query`.                                         |
| `query_with_metadata(request=None, **kwargs)` | Like `query`, plus execution metadata (request id, timing) and response headers (`QueryWithMetadataResult`). Posts to `/v1/query`. |
| `query_batch(request)`                        | Run several governed queries in one round trip (`QueryBatchResult`). Posts to `/v1/query/batch`.                                   |
| `query_sql_report(request)`                   | Run a read-only SQL-style report over a dataset (`QuerySqlReportResult`). Posts to `/v1/query/sql-report`.                         |
| `plan_decision(request)`                      | Turn a goal and context into a structured decision plan (`DecisionPlanResult`). Posts to `/v1/decisions/plan`.                     |
| `verify(request=None, **kwargs)`              | Check a claim against governed data and return a verdict (`VerifyResult`). Posts to `/v1/verify`.                                  |
| `explain(request=None, **kwargs)`             | Run a query and annotate the resolved plan so you can see how the answer was produced (`ExplainResult`).                           |
| `recommend(actions, **kwargs)`                | Rank candidate actions against an objective. Posts to `/v1/recommend`.                                                             |
| `score(request, scoring_weights=None)`        | Score a scenario or action set, optionally with custom weights. Posts to `/v1/score`.                                              |
| `batch(items)`                                | Run a list of simulation requests together. Posts to `/v1/batch`.                                                                  |
| `compare(scenarios, **kwargs)`                | Compare multiple scenarios side by side. Posts to `/v1/compare`.                                                                   |

{% hint style="info" %}
`plan_decision` lives on this surface (it turns intent into a plan) while the decision-memory methods that record and replay decisions live in [Decisions and products](/sdks/python/decisions-and-products.md).
{% endhint %}

## Example: simulate a scenario

```python
import os
from decision_engine import AlgentaClient

client = AlgentaClient(api_key=os.environ["ALGENTA_API_KEY"])

envelope = client.simulate(
    mode="auto",
    simulation_model="monte_carlo",
    scenario={
        "name": "Product launch decision",
        "variables": {
            "revenue": {"low": 80000, "high": 200000},
            "cost": {"low": 40000, "high": 90000},
        },
        "objective": "maximize_net_value",
    },
    runs=10000,
)

print(envelope.recommended_action, envelope.confidence)
print(envelope.metrics.expected_value)
```

## Example: resolve, query, and batch

```python
import os
from decision_engine import AlgentaClient

client = AlgentaClient(api_key=os.environ["ALGENTA_API_KEY"])

# Resolve a hint into a typed plan, then run a query with metadata.
plan = client.resolve({"dataset_id": "$DATASET_ID", "metric": {"hint": "revenue"}})

result = client.query_with_metadata(
    {
        "dataset_id": "$DATASET_ID",
        "metric": {"hint": "revenue"},
        "aggregation": "sum",
    }
)
print(result.metadata.request_id, result.data)

# Run several governed queries in one round trip.
batch = client.query_batch(
    {
        "queries": [
            {"dataset_id": "$DATASET_ID", "metric": {"hint": "revenue"}, "aggregation": "sum"},
            {"dataset_id": "$DATASET_ID", "metric": {"hint": "orders"}, "aggregation": "count"},
        ]
    }
)
print(batch.results)
```

## Related pages

{% content-ref url="/pages/xo3kyzyPZXFb0ETopz2h" %}
[Simulate a scenario](/guides/simulate.md)
{% endcontent-ref %}

{% content-ref url="/pages/1hWq4uaSOQ9pNlD9Ox0f" %}
[Query governed data](/guides/governed-query.md)
{% endcontent-ref %}

{% content-ref url="/pages/azHBRVU9OvmCqePoXOAt" %}
[Decisions & products](/sdks/python/decisions-and-products.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.algenta.ai/sdks/python/simulations-and-queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
