> 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/typescript/decisions-and-products.md).

# Decisions & products

These `AlgentaClient` methods cover two families: **decision memory** — persisting the decisions you make and the outcomes you observe (`logDecision`, `listDecisions`, `getDecision`, `recordOutcome`, `executeDecision`, `deleteDecision`) — and the high-level **product endpoints** that wrap common workflows (`productDecision`, `productOptimize`, `productForecast`, `productRetrieve`, `productAgentRun`). Method names are `camelCase`; bodies stay `snake_case`.

## Decision memory methods

Log a decision when you make it, then record the real outcome later so the engine can learn. `logDecision` requires only `chosen_action`; `recordOutcome` requires `actual_outcome`.

```typescript
import { AlgentaClient } from "algenta-sdk";

const client = new AlgentaClient({ apiKey: process.env.ALGENTA_API_KEY });

// 1. Record the decision you made.
const logged = await client.logDecision({
  chosen_action: "launch_now",
  context: "Q3 product launch",
  options_considered: ["launch_now", "wait_a_quarter"],
  expected_value: 142000,
  confidence: 0.81,
  rationale: "Upside outweighs the delay risk.",
});

// 2. Later, attach the observed outcome.
const withOutcome = await client.recordOutcome(logged.id, {
  actual_outcome: 137500,
  outcome_notes: "Slightly under forecast; supply delay.",
});
console.log(withOutcome.id, withOutcome.actual_outcome);

// 3. Browse decisions that already have an outcome.
const page = await client.listDecisions({ page: 1, limit: 25, with_outcome_only: true });
console.log(page);
```

| Method                                 | HTTP                               | Notes                                                                                                         |
| -------------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `logDecision(request)`                 | `POST /v1/decisions`               | `request` is a `LogDecisionRequest`; only `chosen_action` is required.                                        |
| `listDecisions(options?)`              | `GET /v1/decisions`                | Paginate with `page`, `limit`, `page_size`; `with_outcome_only` filters to decisions with a recorded outcome. |
| `getDecision(decisionId)`              | `GET /v1/decisions/{id}`           | Fetch one logged decision.                                                                                    |
| `recordOutcome(decisionId, request)`   | `PATCH /v1/decisions/{id}/outcome` | `request` is a `RecordOutcomeRequest` (`actual_outcome`, `outcome_notes`).                                    |
| `executeDecision(decisionId, request)` | `POST /v1/decisions/{id}/execute`  | `request` is an `ExecuteDecisionRequest`; `webhook_url` is required.                                          |
| `deleteDecision(decisionId)`           | `DELETE /v1/decisions/{id}`        | Removes a logged decision.                                                                                    |

{% hint style="warning" %}
`executeDecision` posts to a `webhook_url` you supply. Set `timeout_seconds` for slow endpoints, and only pass `force` or `override_safety` when you intend to bypass the engine's safety checks.
{% endhint %}

## Product methods

The product endpoints are self-contained wrappers over common decision workflows — you pass a domain-shaped request and get a domain-shaped response, no scenario wiring required.

```typescript
// A decision from labeled inputs.
const decision = await client.productDecision({
  inputs: [
    { name: "revenue", value: 140000, low: 80000, high: 200000, unit: "USD" },
    { name: "cost", value: 65000, low: 40000, high: 90000, unit: "USD" },
  ],
  objective: "maximize_net_value",
  risk_tolerance: "balanced",
  scenarios: 10000,
});
console.log(decision);

// A forecast from a metric history.
const forecast = await client.productForecast({
  metric: "weekly_active_users",
  history: [1200, 1315, 1402, 1490, 1555],
  horizon: 4,
  seasonality: true,
  confidence_level: 0.9,
});
console.log(forecast);
```

| Method                     | HTTP                 | Notes                                                                                                          |
| -------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------- |
| `productDecision(request)` | `POST /v1/decision`  | `inputs` is an array of `{ name, value, low?, high?, unit? }`; add `objective`, `risk_tolerance`, `scenarios`. |
| `productOptimize(request)` | `POST /v1/optimize`  | `objective` plus `variables` (`{ name, min, max, step? }`); optional `constraints`, `iterations`.              |
| `productForecast(request)` | `POST /v1/forecast`  | `metric` and a numeric `history`; optional `horizon`, `seasonality`, `confidence_level`.                       |
| `productRetrieve(request)` | `POST /v1/retrieve`  | `query` plus inline `documents` or a `collection_id`; optional `top_k`, `rerank`.                              |
| `productAgentRun(request)` | `POST /v1/agent/run` | `task` to run through the tool loop; optional `context`, `tools`, `max_steps`, `output_format`.                |

## Next steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Simulate and query</strong></td><td>Run Monte Carlo decisions and governed data queries.</td><td><a href="/pages/ajpMQ9mrTXbAhImUrKTA">/pages/ajpMQ9mrTXbAhImUrKTA</a></td></tr><tr><td><strong>Use the LLM surface</strong></td><td>Chat, embeddings, tokenization, and model discovery.</td><td><a href="/pages/GLLzjTADRlrAr07CtKVA">/pages/GLLzjTADRlrAr07CtKVA</a></td></tr><tr><td><strong>Set up the client</strong></td><td>Install, configure, and handle errors.</td><td><a href="/pages/94zbz2BEgat0o5aXo4iU">/pages/94zbz2BEgat0o5aXo4iU</a></td></tr></tbody></table>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.algenta.ai/sdks/typescript/decisions-and-products.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
