Skip to content

Commit 3064160

Browse files
Grafi 48/simplify events (#71)
* consistant and simplify * simplify event and record * lint and unit tests * update unit tests * update code * lint * update tracer * fix lint * update version, minor changes
1 parent 88e82de commit 3064160

119 files changed

Lines changed: 6117 additions & 3139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/docs/guide/configuring-event-store.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ print(f"Events: {events} ")
247247
2025-07-12 17:38:55.895 | DEBUG | grafi.common.instrumentations.tracing:is_local_endpoint_available:30 - Endpoint check failed: [Errno 111] Connection refused
248248
2025-07-12 17:38:55.895 | DEBUG | grafi.common.instrumentations.tracing:setup_tracing:117 - OTLP endpoint is not available. Using InMemorySpanExporter.
249249
2025-07-12 17:38:55.905 | INFO | grafi.common.topics.topic:publish_data:64 - [agent_input_topic] Message published with event_id: 1da4f45008264dc98fd63dc154dcaa6e
250-
2025-07-12 17:38:55.912 | DEBUG | grafi.nodes.node:invoke:49 - Executing Node with inputs: [ConsumeFromTopicEvent(event_id='8dd13f159fbc40b29ca030501f4d2859', event_version='1.0', invoke_context=InvokeContext(conversation_id='9051491ca7a84b71a3f3e9d790b79e4f', invoke_id='6e56da25ca824bf4a8d454a731b6f336', assistant_request_id='0e0317d25c9b40e4a76a130bbbb7bc43', user_id='9e396be8f8c442bc9269a31a9b3f69a2'), event_type=<EventType.CONSUME_FROM_TOPIC: 'ConsumeFromTopic'>, timestamp=datetime.datetime(2025, 7, 12, 16, 38, 55, 909090, tzinfo=datetime.timezone.utc), topic_name='agent_input_topic', offset=0, data=[Message(name=None, message_id='ae2638fa5f3047fbbfb43dbd1545e6d2', timestamp=1752338335885634346, content='What is the capital of the United Kingdom', refusal=None, annotations=None, audio=None, role='user', tool_call_id=None, tools=None, function_call=None, tool_calls=None, is_streaming=False)], consumer_name='OpenAIInputNode', consumer_type='OpenAIInputNode')]
250+
2025-07-12 17:38:55.912 | DEBUG | grafi.nodes.node:invoke:49 - Executing Node with inputs: [ConsumeFromTopicEvent(event_id='8dd13f159fbc40b29ca030501f4d2859', event_version='1.0', invoke_context=InvokeContext(conversation_id='9051491ca7a84b71a3f3e9d790b79e4f', invoke_id='6e56da25ca824bf4a8d454a731b6f336', assistant_request_id='0e0317d25c9b40e4a76a130bbbb7bc43', user_id='9e396be8f8c442bc9269a31a9b3f69a2'), event_type=<EventType.CONSUME_FROM_TOPIC: 'ConsumeFromTopic'>, timestamp=datetime.datetime(2025, 7, 12, 16, 38, 55, 909090, tzinfo=datetime.timezone.utc), name='agent_input_topic', offset=0, data=[Message(name=None, message_id='ae2638fa5f3047fbbfb43dbd1545e6d2', timestamp=1752338335885634346, content='What is the capital of the United Kingdom', refusal=None, annotations=None, audio=None, role='user', tool_call_id=None, tools=None, function_call=None, tool_calls=None, is_streaming=False)], consumer_name='OpenAIInputNode', consumer_type='OpenAIInputNode')]
251251
2025-07-12 17:38:57.400 | INFO | grafi.common.topics.topic:publish_data:69 - [function_call_topic] Message NOT published (condition not met)
252252
2025-07-12 17:38:57.400 | INFO | grafi.common.topics.output_topic:publish_data:91 - [agent_output_topic] Message published with event_id: d83d3339fbd94d6e983fc51965177891
253253
<span style="color:#FF4689">Output from React Agent:</span> The capital of the United Kingdom is London.

docs/docs/user-guide/assistant.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class MyAssistant(AssistantBase):
2626
# Implementation required
2727
pass
2828

29-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
29+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
3030
# Implementation required
3131
pass
3232

33-
async def a_invoke(self, input_event: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
33+
async def a_invoke(self, input_data: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
3434
# Implementation required
3535
pass
3636
```
@@ -87,14 +87,14 @@ Synchronously processes input events through the configured workflow.
8787

8888
```python
8989
@record_assistant_invoke
90-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
91-
events = self.workflow.invoke(input_event)
90+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
91+
events = self.workflow.invoke(input_data)
9292
return events
9393
```
9494

9595
**Parameters**:
9696

97-
- `input_event`: A `PublishToTopicEvent` containing the data to be processed and context information
97+
- `input_data`: A `PublishToTopicEvent` containing the data to be processed and context information
9898

9999
**Returns**: List of `ConsumeFromTopicEvent` objects representing the workflow output
100100

@@ -106,14 +106,14 @@ Asynchronously processes input events with support for streaming responses.
106106

107107
```python
108108
@record_assistant_a_invoke
109-
async def a_invoke(self, input_event: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
110-
async for output in self.workflow.a_invoke(input_event):
109+
async def a_invoke(self, input_data: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
110+
async for output in self.workflow.a_invoke(input_data):
111111
yield output
112112
```
113113

114114
**Parameters**:
115115

116-
- `input_event`: A `PublishToTopicEvent` containing the data to be processed and context information
116+
- `input_data`: A `PublishToTopicEvent` containing the data to be processed and context information
117117

118118
**Returns**: Async generator yielding `ConsumeFromTopicEvent` objects
119119

docs/docs/user-guide/event-driven-workflow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ async def _invoke_node(self, invoke_context: InvokeContext, node: Node):
234234
published_events = await a_publish_events(...)
235235
# Notify downstream nodes immediately
236236
for event in published_events:
237-
if event.topic_name in self._topic_nodes:
238-
topic = self._topics[event.topic_name]
237+
if event.name in self._topic_nodes:
238+
topic = self._topics[event.name]
239239
async with topic.event_cache._cond:
240240
topic.event_cache._cond.notify_all()
241241

docs/docs/user-guide/event-interfaces.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Created when data is consumed from a topic:
5959
from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFromTopicEvent
6060

6161
event = ConsumeFromTopicEvent(
62-
topic_name="output_topic",
62+
name="output_topic",
63+
type=TopicType.DEFAULT_TOPIC_TYPE,
6364
offset=42,
6465
publisher_name="ProcessorNode", # Original publisher
6566
publisher_type="node",
@@ -80,18 +81,18 @@ from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFro
8081
from typing import List, AsyncGenerator
8182

8283
class MyAssistant(Assistant):
83-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
84+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
8485
"""Synchronous processing of events."""
8586
# Delegate to workflow
86-
events = self.workflow.invoke(input_event)
87+
events = self.workflow.invoke(input_data)
8788
return events
8889

8990
async def a_invoke(
9091
self,
91-
input_event: PublishToTopicEvent
92+
input_data: PublishToTopicEvent
9293
) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
9394
"""Asynchronous streaming of events."""
94-
async for output in self.workflow.a_invoke(input_event):
95+
async for output in self.workflow.a_invoke(input_data):
9596
yield output
9697
```
9798

@@ -132,10 +133,10 @@ from grafi.common.events.topic_events.publish_to_topic_event import PublishToTop
132133
from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFromTopicEvent
133134

134135
class MyWorkflow(Workflow):
135-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
136+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
136137
"""Execute workflow synchronously."""
137138
# Initialize workflow with input event
138-
self.initial_workflow(input_event)
139+
self.initial_workflow(input_data)
139140

140141
# Process nodes until completion
141142
while not self._invoke_queue.empty():
@@ -185,8 +186,8 @@ def invoke(self, invoke_context: InvokeContext, input_data: Messages) -> Message
185186

186187
**New Pattern:**
187188
```python
188-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
189-
return self.workflow.invoke(input_event)
189+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
190+
return self.workflow.invoke(input_data)
190191
```
191192

192193
Key changes:

docs/docs/user-guide/events/event_graph.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ graph TD
7777
```python
7878
# Create mapping for efficient lookup
7979
topic_offset_to_publish = {
80-
f"{event.topic_name}::{event.offset}": event
80+
f"{event.name}::{event.offset}": event
8181
for event in topic_events.values()
8282
if isinstance(event, PublishToTopicEvent)
8383
}
@@ -94,7 +94,7 @@ def build_node_relations(consume_event: ConsumeFromTopicEvent) -> None:
9494
current_node = self._add_event(consume_event)
9595

9696
# Find corresponding publish event
97-
publish_key = f"{consume_event.topic_name}::{consume_event.offset}"
97+
publish_key = f"{consume_event.name}::{consume_event.offset}"
9898
publish_event = topic_offset_to_publish.get(publish_key)
9999

100100
if publish_event:
@@ -278,7 +278,7 @@ def find_root_causes(graph: EventGraph):
278278
{
279279
"event_id": node.event_id,
280280
"timestamp": node.event.timestamp,
281-
"topic_name": node.event.topic_name,
281+
"name": node.event.name,
282282
"downstream_count": len(node.downstream_events)
283283
}
284284
for node in root_nodes
@@ -401,7 +401,7 @@ def save_graph_to_event_store(graph: EventGraph, event_store: EventStore):
401401
from grafi.common.events.topic_events.topic_event import TopicEvent
402402

403403
graph_event = TopicEvent(
404-
topic_name="event_graph_analysis",
404+
name="event_graph_analysis",
405405
offset=0,
406406
data=graph.to_dict()
407407
)

docs/docs/user-guide/events/events.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ Basic event for topic-related activities.
273273

274274
| Field | Type | Description |
275275
|--------------|----------------|----------------------------------------------------|
276-
| `topic_name` | `str` | Name of the topic. |
277-
| `topic_type` | `TopicType` | Type of the topic. |
276+
| `name` | `str` | Name of the topic. |
277+
| `type` | `TopicType` | Type of the topic. |
278278
| `offset` | `int` | Position/offset in the topic stream. |
279279
| `data` | `List[Message]`| Data associated with the topic event. |
280280

@@ -370,7 +370,8 @@ Each event type includes structured context information:
370370
"consumed_event_ids": ["event_1", "event_2"],
371371
"publisher_name": "Data Processor",
372372
"publisher_type": "ProcessingNode",
373-
"topic_name": "output_topic",
373+
"name": "output_topic",
374+
"type": "topic",
374375
"offset": 42,
375376
"invoke_context": {...}
376377
}

docs/docs/user-guide/invoke-decorators.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ from grafi.common.events.topic_events.publish_to_topic_event import PublishToTop
9090
from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFromTopicEvent
9191

9292
@record_assistant_invoke
93-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
93+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
9494
# Assistant implementation
95-
return self.workflow.invoke(input_event)
95+
return self.workflow.invoke(input_data)
9696
```
9797

9898
#### @record_assistant_a_invoke
@@ -117,9 +117,9 @@ from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFro
117117
from typing import AsyncGenerator
118118

119119
@record_assistant_a_invoke
120-
async def a_invoke(self, input_event: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
120+
async def a_invoke(self, input_data: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
121121
# Async assistant implementation
122-
async for output in self.workflow.a_invoke(input_event):
122+
async for output in self.workflow.a_invoke(input_data):
123123
yield output
124124
```
125125

@@ -201,7 +201,7 @@ async def a_invoke(self, invoke_context: InvokeContext,
201201

202202
#### @record_tool_invoke
203203

204-
**Location**: `grafi.common.decorators.record_tool_invoke`
204+
**Location**: `grafi.common.decorators.record_decorators`
205205

206206
Records synchronous tool invocations with event logging and tracing.
207207

@@ -215,7 +215,7 @@ Records synchronous tool invocations with event logging and tracing.
215215
**Usage**:
216216

217217
```python
218-
from grafi.common.decorators.record_tool_invoke import record_tool_invoke
218+
from grafi.common.decorators.record_decorators import record_tool_invoke
219219

220220
@record_tool_invoke
221221
def invoke(self, invoke_context: InvokeContext, input_data: Messages) -> Messages:
@@ -225,7 +225,7 @@ def invoke(self, invoke_context: InvokeContext, input_data: Messages) -> Message
225225

226226
#### @record_tool_a_invoke
227227

228-
**Location**: `grafi.common.decorators.record_tool_a_invoke`
228+
**Location**: `grafi.common.decorators.record_decorators`
229229

230230
Records asynchronous tool invocations that return async generators.
231231

@@ -239,7 +239,7 @@ Records asynchronous tool invocations that return async generators.
239239
**Usage**:
240240

241241
```python
242-
from grafi.common.decorators.record_tool_a_invoke import record_tool_a_invoke
242+
from grafi.common.decorators.record_decorators import record_tool_a_invoke
243243

244244
@record_tool_a_invoke
245245
async def a_invoke(self, invoke_context: InvokeContext, input_data: Messages) -> MsgsAGen:
@@ -271,7 +271,7 @@ from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFro
271271
from typing import List
272272

273273
@record_workflow_invoke
274-
def invoke(self, input_event: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
274+
def invoke(self, input_data: PublishToTopicEvent) -> List[ConsumeFromTopicEvent]:
275275
# Workflow orchestration logic
276276
# Initialize workflow, execute nodes, return consumed events
277277
return output_events
@@ -299,10 +299,10 @@ from grafi.common.events.topic_events.consume_from_topic_event import ConsumeFro
299299
from typing import AsyncGenerator
300300

301301
@record_workflow_a_invoke
302-
async def a_invoke(self, input_event: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
302+
async def a_invoke(self, input_data: PublishToTopicEvent) -> AsyncGenerator[ConsumeFromTopicEvent, None]:
303303
# Async workflow orchestration
304304
# Initialize workflow, execute nodes asynchronously, yield consumed events
305-
async for output_event in self._execute_workflow(input_event):
305+
async for output_event in self._execute_workflow(input_data):
306306
yield output_event
307307
```
308308

docs/docs/user-guide/models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ from grafi.tools.tool import Tool
104104
command = Command.for_tool(my_tool)
105105

106106
# Invoke the command
107-
response = command.invoke(invoke_context, input_events)
107+
response = command.invoke(invoke_context, input_datas)
108108
```
109109

110110
## FunctionSpec

docs/docs/user-guide/node.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ from grafi.common.events.topic_events.publish_to_topic_event import PublishToTop
100100

101101
# Synchronous invocation
102102
context = InvokeContext(session_id="session-123")
103-
input_events = [ConsumeFromTopicEvent(...)] # List of consumed events
104-
output_event: PublishToTopicEvent = node.invoke(context, input_events)
103+
input_datas = [ConsumeFromTopicEvent(...)] # List of consumed events
104+
output_event: PublishToTopicEvent = node.invoke(context, input_datas)
105105

106106
# Asynchronous invocation
107-
async for output_event in node.a_invoke(context, input_events):
107+
async for output_event in node.a_invoke(context, input_datas):
108108
# Process each PublishToTopicEvent as it's generated
109109
pass
110110
```

docs/docs/user-guide/topics/input_topics.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ output_event = workflow_output_topic.publish_data(
174174

175175
# When user responds, publish to paired input topic
176176
user_response = [Message(role="user", content="Approved")]
177-
input_event = workflow_input_topic.publish_input_data(
177+
input_data = workflow_input_topic.publish_input_data(
178178
upstream_event=output_event,
179179
data=user_response
180180
)
@@ -213,12 +213,12 @@ async def human_approval_workflow():
213213

214214
# Process user response
215215
user_feedback = [Message(role="user", content="Looks good, approved!")]
216-
input_event = await input_topic.a_publish_input_data(
216+
input_data = await input_topic.a_publish_input_data(
217217
upstream_event=output_event,
218218
data=user_feedback
219219
)
220220

221-
return input_event
221+
return input_data
222222
```
223223

224224
## Best Practices
@@ -325,14 +325,14 @@ async def test_input_topics():
325325

326326
# Simulate user response
327327
user_response = [Message(role="user", content="Here's my input")]
328-
input_event = await workflow_input_topic.a_publish_input_data(
328+
input_data = await workflow_input_topic.a_publish_input_data(
329329
upstream_event=output_event,
330330
data=user_response
331331
)
332332

333-
assert input_event is not None
334-
assert input_event.data == user_response
335-
assert input_event.consumed_events == [output_event]
333+
assert input_data is not None
334+
assert input_data.data == user_response
335+
assert input_data.consumed_events == [output_event]
336336
```
337337

338338
## Topic Type Constants

0 commit comments

Comments
 (0)