Find answers from the community

Updated 2 months ago

Passing-context-to-set-account-balance-in-workflow

Hi, I’m trying to understand this code from the https://github.com/run-llama/multi-agent-concierge/blob/main/workflows.py#L274
I need to from utils import get_account_balance and use it within that workflow. However, I’m confused about how to pass the context (ctx) so that I can set ctx.data["user"]["account_balance"] = 1000.

Does anyone know how can I achieve this?
L
N
10 comments
thats correct but if i have

Plain Text
def get_account_balance(account_id: str) -> str:
                """Useful for looking up an account balance."""
                print(f"Looking up account balance for {account_id}")
                ctx.data["user"]["account_balance"] = 1000
                return f"Account {account_id} has a balance of ${ctx.data['user']['account_balance']}"
in other file, ctx is undefined
Right, thats why its defined as a nested function

If you want to define it in another file, you still need some wrapper defined as a nested function so that you can pass in the context from the parent scope
how would that look like?
Plain Text
def account_balance(self, ctx: Context, ev: AccountBalanceEvent) -> AuthenticateEvent | ConciergeEvent:
  ...
  def get_account_balance(account_id: str):
    return actual_get_account_balance(account_id, ctx)
Something like that
that worked!! thanks 👍
Add a reply
Sign up and join the conversation on Discord