Skip to content

trading_agent.requests.plan_response

The user's decision on a desk's plan: approve it, or ask for changes with feedback.

Typical usage example:

response = PlanResponse(request, 'revise', 'Smaller size on the first trade') response.check() text = response.message()

APPROVE module-attribute

APPROVE = 'approve'

REVISE module-attribute

REVISE = 'revise'

PlanResponse

PlanResponse(request, decision, feedback)

Approve, or keep planning with the user's feedback.

Creates the response.

Parameters:

Name Type Description Default
request UserRequest

The plan request.

required
decision str

"approve" or "revise".

required
feedback str

What the user wants changed, or a note with an approval.

required
Source code in src/trading_agent/requests/plan_response.py
def __init__(
    self,
    request: user_request_module.UserRequest,
    decision: str,
    feedback: str,
):
    """Creates the response.

    Args:
        request (user_request_module.UserRequest): The plan request.
        decision (str): "approve" or "revise".
        feedback (str): What the user wants changed, or a note with an approval.
    """
    self._request = request
    self._decision = decision
    self._feedback = feedback.strip()

check

check()

Checks the decision.

Raises:

Type Description
ValueError

The decision is neither "approve" nor "revise", or a revision has no feedback.

Source code in src/trading_agent/requests/plan_response.py
def check(self) -> None:
    """Checks the decision.

    Raises:
        ValueError: The decision is neither "approve" nor "revise", or a revision has no feedback.
    """
    if self._decision not in (APPROVE, REVISE):
        raise ValueError(f'A plan is approved or revised, not {self._decision!r}')
    if self._decision == REVISE and not self._feedback:
        raise ValueError('Say what should change in the plan')

stored

stored()

The response as saved with the request.

Returns:

Type Description
dict[str, Any]

The decision and the feedback.

Source code in src/trading_agent/requests/plan_response.py
def stored(self) -> dict[str, Any]:
    """The response as saved with the request.

    Returns:
        dict[str, Any]: The decision and the feedback.
    """
    return {
        'decision': self._decision,
        'feedback': self._feedback,
    }

message

message()

The message the desk receives.

Returns:

Type Description
str

The decision, with the feedback.

Source code in src/trading_agent/requests/plan_response.py
def message(self) -> str:
    """The message the desk receives.

    Returns:
        str: The decision, with the feedback.
    """
    title = self._request.title()
    if self._decision == APPROVE:
        text = f'The user approved your plan "{title}" (request {self._request.request_id}). Carry it out within the rules.'
        if self._feedback:
            text = f'{text}\nThey added: {self._feedback}'
        return text
    return f'The user wants changes to your plan "{title}" (request {self._request.request_id}) before you act on it:\n{self._feedback}\nRevise the plan and present it again with present_plan.'