Response As Variable
Capture agent responses as variables for downstream use.
Response As Variable.
1"""2Response As Variable3=============================45Response As Variable.6"""78from typing import Iterator # noqa9from rich.pretty import pprint10from kern.agent import Agent, RunOutput11from kern.models.openai import OpenAIResponses12from kern.tools.yfinance import YFinanceTools1314# ---------------------------------------------------------------------------15# Create Agent16# ---------------------------------------------------------------------------17agent = Agent(18 model=OpenAIResponses(id="gpt-5.2"),19 tools=[YFinanceTools()],20 instructions=["Use tables where possible"],21 markdown=True,22)2324# ---------------------------------------------------------------------------25# Run Agent26# ---------------------------------------------------------------------------27if __name__ == "__main__":28 run_response: RunOutput = agent.run("What is the stock price of NVDA")29 pprint(run_response)3031 # run_response_strem: Iterator[RunOutputEvent] = agent.run("What is the stock price of NVDA", stream=True)32 # for response in run_response_strem:33 # pprint(response)Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/02_input_output45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python response_as_variable.py