decision_close

Closes a decision envelope by either committing (finalizing) or aborting (rolling back) the decision.

Overview

The decision_close method finalizes a decision envelope. You must close every decision you create - either by committing it (making the operations permanent) or aborting it (rolling back all operations). This is a critical step in the decision lifecycle.

Request

Parameters

ParameterTypeRequiredDescription
decision_idstringYesThe decision ID to close
actionstringYesEither "commit" to finalize or "abort" to rollback
summaryobjectNoSummary of the decision (any JSON object)
reasonstringNoHuman-readable reason for closing the decision

Actions

  • commit - Finalizes the decision and makes all operations permanent. Committed decisions are immutable and auditable.
  • abort - Rolls back the decision and cancels all operations. Aborted decisions indicate the agent cancelled the operation.

Example Request

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "decision_close",
    "arguments": {
      "decision_id": "TMEM_abc123...",
      "action": "commit",
      "summary": {
        "order_id": 12345,
        "total_amount": 299.99,
        "items_count": 3
      },
      "reason": "Order successfully created and validated"
    }
  }
}

Response

Success Response

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\"decision_id\": \"TMEM_abc123...\", \"status\": \"committed\", \"closed_at\": \"2026-01-07T12:05:00Z\"}"
      }
    ]
  }
}

Response Fields

FieldTypeDescription
decision_idstringThe decision envelope identifier
statusstringFinal status: "committed" or "aborted"
closed_atstringISO 8601 timestamp when the decision was closed

Error Cases

Missing Required Parameters

Error Code: -32600 (Invalid Request)

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32600,
    "message": "Invalid Request",
    "data": "decision_id and action are required"
  }
}

Invalid Action

Error Code: -32602 (Invalid params)

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32602,
    "message": "Invalid params",
    "data": "action must be either 'commit' or 'abort'"
  }
}

Decision Already Closed

Error Code: -32603 (Internal error)

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Internal error",
    "data": "Decision is already closed"
  }
}

Decision Not Found

Error Code: -32603 (Internal error)

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Internal error",
    "data": "Decision not found"
  }
}

Permission Denied

HTTP Status: 403 Forbidden

Occurs when:

  • The decision belongs to a different agent
  • The API key doesn't have permission to close this decision

Authentication Errors

HTTP Status: 401 Unauthorized

Occurs when:

  • API key is missing
  • API key is invalid
  • API key has been revoked

Usage Examples

Commit a Successful Decision

python
import requests

def close_decision(decision_id, action, summary=None, reason=None, api_key=None):
    response = requests.post('https://mcp.tracemem.com',
        headers={'Authorization': f'Agent {api_key}'},
        json={
            "jsonrpc": "2.0",
            "id": 1,
            "method": "tools/call",
            "params": {
                "name": "decision_close",
                "arguments": {
                    "decision_id": decision_id,
                    "action": action,
                    "summary": summary,
                    "reason": reason
                }
            }
        })
    return response.json()

# Commit successful operation
result = close_decision(
    decision_id="TMEM_abc123...",
    action="commit",
    summary={"order_id": 12345, "status": "created"},
    reason="Order successfully processed",
    api_key="YOUR_API_KEY"
)

Abort on Error

python
try:
    # Perform operations...
    decision_id = create_decision(...)
    read_data(decision_id, ...)
    write_data(decision_id, ...)
    
    # Commit if successful
    close_decision(decision_id, "commit", api_key=api_key)
    
except Exception as e:
    # Abort on any error
    close_decision(decision_id, "abort", 
                   reason=f"Error occurred: {str(e)}",
                   api_key=api_key)
    raise

Using Context Manager Pattern

python
class DecisionContext:
    def __init__(self, intent, automation_mode, api_key):
        self.api_key = api_key
        self.decision_id = None
        decision = create_decision(intent, automation_mode, api_key)
        self.decision_id = decision["decision_id"]
    
    def __enter__(self):
        return self
    
    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type is None:
            close_decision(self.decision_id, "commit", api_key=self.api_key)
        else:
            close_decision(self.decision_id, "abort", 
                          reason=str(exc_val), api_key=self.api_key)
        return False

# Usage
with DecisionContext("customer.order.create", "propose", api_key) as decision:
    # Perform operations...
    read_data(decision.decision_id, ...)
    write_data(decision.decision_id, ...)
    # Automatically commits on success, aborts on exception

Best Practices

  1. Always close decisions: Every decision you create must be closed. Never leave decisions open indefinitely.

  2. Use try/except: Wrap decision operations in try/except blocks to ensure decisions are closed even on errors.

  3. Commit on success, abort on failure: Commit when operations complete successfully, abort when errors occur or operations are cancelled.

  4. Include meaningful summaries: Provide summary information that will be useful for auditing and understanding what the decision accomplished.

  5. Provide reasons for aborts: When aborting, include a reason explaining why the decision was cancelled.

  6. Check status before closing: Use decision_get to verify the decision is in a state that can be closed (e.g., not already closed).

  7. Handle approval states: If a decision requires approval, ensure it's approved before committing, or abort if approval is denied.

Important Notes

  • Committed decisions are permanent: Once a decision is committed, it cannot be changed or rolled back. All operations within that decision are final.

  • Aborted decisions are auditable: Even aborted decisions are recorded in the audit trail, showing that the agent attempted an operation but cancelled it.

  • Writes are only committed on close: Data writes performed with decision_write are only made permanent when you close the decision with action: "commit".

  • Approval may be required: If a decision requires approval (status is needs_approval), you may need to wait for approval before committing.

Related Methods

TraceMem is trace-native infrastructure for AI agents