|
6 | 6 | from datetime import datetime, timezone |
7 | 7 | from typing import Any, Callable, Dict, Optional, Sequence |
8 | 8 |
|
| 9 | +from dapr.clients import DaprClient |
9 | 10 | from dapr.clients.grpc._state import Concurrency, Consistency, StateOptions |
| 11 | +from dapr.clients.grpc._response import GetMetadataResponse, RegisteredComponents |
10 | 12 | from pydantic import BaseModel, ValidationError |
11 | 13 |
|
12 | 14 | from dapr_agents.agents.configs import ( |
|
18 | 20 | StateModelBundle, |
19 | 21 | ) |
20 | 22 | from dapr_agents.agents.schemas import AgentWorkflowEntry |
21 | | -from dapr_agents.storage.daprstores.stateservice import StateStoreError |
| 23 | +from dapr_agents.storage.daprstores.stateservice import ( |
| 24 | + StateStoreError, |
| 25 | + StateStoreService, |
| 26 | +) |
22 | 27 | from dapr_agents.types.workflow import DaprWorkflowStatus |
23 | 28 |
|
24 | 29 | logger = logging.getLogger(__name__) |
@@ -63,6 +68,37 @@ def __init__( |
63 | 68 | self.name = name |
64 | 69 | self._workflow_grpc_options = workflow_grpc_options |
65 | 70 |
|
| 71 | + if pubsub is None or state is None or registry is None: |
| 72 | + with DaprClient() as _client: |
| 73 | + resp: GetMetadataResponse = _client.get_metadata() |
| 74 | + components: Sequence[RegisteredComponents] = resp.registered_components |
| 75 | + for component in components: |
| 76 | + if ( |
| 77 | + "state" in component.type |
| 78 | + and component.name == "agent-wfstatestore" |
| 79 | + and state is None |
| 80 | + ): |
| 81 | + state = AgentStateConfig( |
| 82 | + store=StateStoreService(store_name=component.name), |
| 83 | + state_key=f"{name.replace(' ', '-').lower() if name else 'default'}:workflow_state", |
| 84 | + ) |
| 85 | + if component.name == "agent-registry" and registry is None: |
| 86 | + registry = AgentRegistryConfig( |
| 87 | + store=StateStoreService(store_name="agent-registry"), |
| 88 | + team_name="default", |
| 89 | + ) |
| 90 | + if ( |
| 91 | + "pubsub" in component.type |
| 92 | + and component.name == "agent-pubsub" |
| 93 | + and pubsub is None |
| 94 | + ): |
| 95 | + logger.info(f"topic: {name}.topic") |
| 96 | + pubsub = AgentPubSubConfig( |
| 97 | + pubsub_name="agent-pubsub", |
| 98 | + agent_topic=f"{name.replace(' ', '-').lower()}.topic", |
| 99 | + broadcast_topic="agents.broadcast", |
| 100 | + ) |
| 101 | + |
66 | 102 | # ----------------------------- |
67 | 103 | # Pub/Sub configuration (copy) |
68 | 104 | # ----------------------------- |
|
0 commit comments