hammad-python 0.0.23__py3-none-any.whl → 0.0.25__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hammad/__init__.py +62 -14
- hammad/_main.py +226 -0
- hammad/cli/__init__.py +0 -2
- hammad/cli/plugins.py +3 -1
- hammad/data/__init__.py +4 -5
- hammad/data/types/__init__.py +37 -1
- hammad/data/types/file.py +74 -1
- hammad/data/types/multimodal/__init__.py +14 -2
- hammad/data/types/multimodal/audio.py +106 -2
- hammad/data/types/multimodal/image.py +104 -2
- hammad/data/types/text.py +242 -0
- hammad/genai/__init__.py +73 -0
- hammad/genai/a2a/__init__.py +32 -0
- hammad/genai/a2a/workers.py +552 -0
- hammad/genai/agents/__init__.py +8 -0
- hammad/genai/agents/agent.py +747 -214
- hammad/genai/agents/run.py +421 -12
- hammad/genai/agents/types/agent_response.py +2 -1
- hammad/genai/graphs/__init__.py +125 -0
- hammad/genai/graphs/base.py +1786 -0
- hammad/genai/graphs/plugins.py +316 -0
- hammad/genai/graphs/types.py +638 -0
- hammad/genai/models/language/__init__.py +6 -1
- hammad/genai/models/language/model.py +46 -0
- hammad/genai/models/language/run.py +330 -4
- hammad/genai/models/language/types/language_model_response.py +1 -1
- hammad/genai/types/tools.py +1 -1
- hammad/logging/logger.py +60 -5
- hammad/mcp/__init__.py +3 -0
- hammad/types.py +288 -0
- {hammad_python-0.0.23.dist-info → hammad_python-0.0.25.dist-info}/METADATA +6 -1
- {hammad_python-0.0.23.dist-info → hammad_python-0.0.25.dist-info}/RECORD +34 -32
- hammad/_main/__init__.py +0 -4
- hammad/_main/_fn.py +0 -20
- hammad/_main/_new.py +0 -52
- hammad/_main/_run.py +0 -50
- hammad/_main/_to.py +0 -19
- hammad/cli/_runner.py +0 -265
- {hammad_python-0.0.23.dist-info → hammad_python-0.0.25.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.23.dist-info → hammad_python-0.0.25.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
"""hammad.genai.graphs - Graph-based workflow framework built on pydantic-graph
|
2
|
+
|
3
|
+
This module provides a high-level interface for creating graph-based workflows
|
4
|
+
that integrate seamlessly with hammad's Agent and LanguageModel infrastructure.
|
5
|
+
|
6
|
+
Key Features:
|
7
|
+
- Action decorator system for defining graph nodes
|
8
|
+
- Automatic integration with Agent and LanguageModel
|
9
|
+
- IDE-friendly type hints and parameter unpacking
|
10
|
+
- Plugin system for extensibility
|
11
|
+
- Built on pydantic-graph for robust execution
|
12
|
+
|
13
|
+
Basic Usage:
|
14
|
+
from hammad.genai.graphs import BaseGraph, action
|
15
|
+
from pydantic import BaseModel
|
16
|
+
|
17
|
+
class MyState(BaseModel):
|
18
|
+
count: int = 0
|
19
|
+
|
20
|
+
class CountingGraph(BaseGraph[MyState, str]):
|
21
|
+
@action.start()
|
22
|
+
def start_counting(self, ctx, agent, target: int):
|
23
|
+
# Use agent for AI operations
|
24
|
+
response = agent.run(f"Count from 1 to {target}")
|
25
|
+
return response.output
|
26
|
+
|
27
|
+
# Usage
|
28
|
+
graph = CountingGraph()
|
29
|
+
result = graph.run(target=5)
|
30
|
+
print(result.output)
|
31
|
+
|
32
|
+
Advanced Usage with Plugins:
|
33
|
+
from hammad.genai.graphs import plugin
|
34
|
+
|
35
|
+
@plugin.history(summarize=True)
|
36
|
+
@plugin.memory(collection_name="counting")
|
37
|
+
class AdvancedGraph(BaseGraph[MyState, str]):
|
38
|
+
@action.start(instructions="You are a helpful counting assistant")
|
39
|
+
def count_with_memory(self, ctx, agent, target: int):
|
40
|
+
# Agent will have instructions and plugins automatically applied
|
41
|
+
return agent.run(f"Count to {target} and remember this session")
|
42
|
+
"""
|
43
|
+
|
44
|
+
from typing import TYPE_CHECKING
|
45
|
+
from ..._internal import create_getattr_importer
|
46
|
+
|
47
|
+
|
48
|
+
if TYPE_CHECKING:
|
49
|
+
from .base import (
|
50
|
+
ActionDecorator,
|
51
|
+
ActionNode,
|
52
|
+
ActionSettings,
|
53
|
+
BaseGraph,
|
54
|
+
GraphBuilder,
|
55
|
+
action,
|
56
|
+
select,
|
57
|
+
SelectionStrategy,
|
58
|
+
)
|
59
|
+
from .types import (
|
60
|
+
GraphContext,
|
61
|
+
GraphResponse,
|
62
|
+
GraphState,
|
63
|
+
BasePlugin,
|
64
|
+
ActionSettings,
|
65
|
+
ActionInfo,
|
66
|
+
GraphEvent,
|
67
|
+
GraphHistoryEntry,
|
68
|
+
GraphStream,
|
69
|
+
GraphResponseChunk,
|
70
|
+
GraphNode,
|
71
|
+
GraphEnd,
|
72
|
+
PydanticGraphContext,
|
73
|
+
)
|
74
|
+
from .plugins import (
|
75
|
+
plugin,
|
76
|
+
PluginDecorator,
|
77
|
+
HistoryPlugin,
|
78
|
+
MemoryPlugin,
|
79
|
+
AudioPlugin,
|
80
|
+
ServePlugin,
|
81
|
+
SettingsPlugin,
|
82
|
+
)
|
83
|
+
|
84
|
+
|
85
|
+
__all__ = (
|
86
|
+
# Core graph classes
|
87
|
+
"BaseGraph",
|
88
|
+
"GraphBuilder",
|
89
|
+
"ActionDecorator",
|
90
|
+
# Action system
|
91
|
+
"action",
|
92
|
+
"ActionNode",
|
93
|
+
"ActionSettings",
|
94
|
+
"ActionInfo",
|
95
|
+
"select",
|
96
|
+
"SelectionStrategy",
|
97
|
+
# Plugin system
|
98
|
+
"plugin",
|
99
|
+
"BasePlugin",
|
100
|
+
"PluginDecorator",
|
101
|
+
"HistoryPlugin",
|
102
|
+
"MemoryPlugin",
|
103
|
+
"AudioPlugin",
|
104
|
+
"ServePlugin",
|
105
|
+
"SettingsPlugin",
|
106
|
+
# Types and context
|
107
|
+
"GraphContext",
|
108
|
+
"GraphResponse",
|
109
|
+
"GraphState",
|
110
|
+
"GraphEvent",
|
111
|
+
"GraphHistoryEntry",
|
112
|
+
"GraphStream",
|
113
|
+
"GraphResponseChunk",
|
114
|
+
# Re-exports from pydantic-graph
|
115
|
+
"GraphNode",
|
116
|
+
"GraphEnd",
|
117
|
+
"PydanticGraphContext",
|
118
|
+
)
|
119
|
+
|
120
|
+
|
121
|
+
__getattr__ = create_getattr_importer(__all__)
|
122
|
+
|
123
|
+
|
124
|
+
def __dir__() -> list[str]:
|
125
|
+
return list(__all__)
|