Execute the workflow with caching logic. This method: 1. Checks if the response is already cached 2. Returns cached response immediately if found 3. Generates new response if not cached 4. Caches the new response for future use Args:
(self, message: str)
| 53 | agent = Agent(model=OpenAIChat(id="gpt-4o-mini"), description="General purpose agent for generating responses") |
| 54 | |
| 55 | def run(self, message: str) -> Iterator[RunResponse]: |
| 56 | """ |
| 57 | Execute the workflow with caching logic. |
| 58 | |
| 59 | This method: |
| 60 | 1. Checks if the response is already cached |
| 61 | 2. Returns cached response immediately if found |
| 62 | 3. Generates new response if not cached |
| 63 | 4. Caches the new response for future use |
| 64 | |
| 65 | Args: |
| 66 | message: The input query to process |
| 67 | |
| 68 | Yields: |
| 69 | RunResponse: Streamed response chunks |
| 70 | """ |
| 71 | logger.info(f"Checking cache for '{message}'") |
| 72 | |
| 73 | if self.session_state.get(message): |
| 74 | logger.info(f"Cache hit for '{message}'") |
| 75 | # Return cached response immediately (no API call needed) |
| 76 | yield RunResponse(run_id=self.run_id, content=self.session_state.get(message)) |
| 77 | return |
| 78 | |
| 79 | logger.info(f"Cache miss for '{message}'") |
| 80 | |
| 81 | yield from self.agent.run(message, stream=True) |
| 82 | |
| 83 | self.session_state[message] = self.agent.run_response.content |
| 84 | logger.info("Cached response for future use") |
| 85 | |
| 86 | |
| 87 | def demonstrate_workflows(): |
no test coverage detected