Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/004/images/main/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ockam import Agent, Knowledge, Model, Node
from ockam import Agent, Memory, Model, Node


async def main(node):
Expand All @@ -11,9 +11,9 @@ async def main(node):
"sec-330e": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330e.md",
}

us_federal_code = Knowledge("us_federal_code")
us_federal_code = StaticKnowledgeProvider("us_federal_code")
for name, url in docs.items():
await us_federal_code.add_document(name, url, content_type="text/markdown")
await us_federal_code.add(name, url, content_type="text/markdown")

await Agent.start(
node=node,
Expand Down
6 changes: 3 additions & 3 deletions examples/005/images/main/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ockam import Agent, Knowledge, Model, Node
from ockam import Agent, Memory, Model, Node


async def main(node):
pioneer_docs = Knowledge("pioneer_ai_documents")
await pioneer_docs.add_document(
pioneer_docs = Memory("pioneer_ai_documents")
await pioneer_docs.add(
"Ownership in Pioneer.ai",
"http://localhost:5555/ownership.md",
content_type="text/markdown",
Expand Down
54 changes: 29 additions & 25 deletions implementations/python/examples/13.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
from ockam import Agent, Model, Node, SearchableKnowledge
from ockam import Agent, Model, Node, Memory
from ockam.knowledge.protocol import Document

"""
This example shows how a model can be enriched with knowledge coming from inlined documents.
"""


async def main(node):
restaurants = SearchableKnowledge(
"restaurants",
model=Model("ollama/nomic-embed-text"),
)
await restaurants.add_text(
"Tony's Pizzeria Menu",
"""
1. Margherita - $10
2. Pepperoni - $12
3. Hawaiian - $11
4. Veggie - $9
5. Four Cheese - $13
""",
restaurants = Memory("restaurants")

await restaurants.add(
Document(
"Tony's Pizzeria Menu",
"""
1. Margherita - $10
2. Pepperoni - $12
3. Hawaiian - $11
4. Veggie - $9
5. Four Cheese - $13
""",
content_type="text/plain",
)
)

await restaurants.add_text(
"Diner Menu",
"""
1. Caesar Salad - $8
2. Vegan Burger - $14
3. Chicken - $15
4. Shrimp Tacos - $16
5. Chocolate Lava Cake - $7
""",
await restaurants.add(
Document.inline(
"Diner Menu",
"""
1. Caesar Salad - $8
2. Vegan Burger - $14
3. Chicken - $15
4. Shrimp Tacos - $16
5. Chocolate Lava Cake - $7
""",
content_type="text/plain",
)
)

agent = await Agent.start(
node=node,
name="Assistant",
instructions="Assistant to solve some complex task ...",
model=Model(name="ollama_chat/llama3.2"),
knowledge=restaurants,
max_knowledge_size=4096,
memory=restaurants,
)

reply = await agent.send("What's the price of a pepperoni pizza?", scope="a", conversation="1")
Expand Down
21 changes: 10 additions & 11 deletions implementations/python/examples/14.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from ockam import Agent, Model, Node, SearchableKnowledge
from ockam import Agent, Model, Node, Memory, Document, SEARCHABLE

"""
This example shows how a model can be enriched with knowledge coming from documents retrieved online.
"""


async def main(node):
ockam_documentation = SearchableKnowledge(
"ockam_documentation",
model=Model("ollama/nomic-embed-text"),
)
ockam_documentation = Memory("ockam_documentation")

base_url = "https://raw.githubusercontent.com/build-trust/ockam-documentation/refs/heads/main"
documents = [
Expand All @@ -22,19 +19,21 @@ async def main(node):
]

for document in documents:
await ockam_documentation.add_document(
document,
f"{base_url}/{document}",
content_type="text/markdown",
await ockam_documentation.add(
Document(
name=document,
url=f"{base_url}/{document}",
content_type="text/markdown",
),
retrieval=SEARCHABLE
)

agent = await Agent.start(
node=node,
name="Assistant",
instructions="Assistant to solve some complex task ...",
model=Model(name="ollama_chat/llama3.2"),
knowledge=ockam_documentation,
max_knowledge_size=4096,
memory=ockam_documentation,
)

reply = await agent.send("What's ockam?", scope="a", conversation="1")
Expand Down
47 changes: 16 additions & 31 deletions implementations/python/python/ockam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .agents import Agent, AgentReference, HttpServer, Repl
from .clusters import Cluster, Zone
from .flows import Flow, FlowOperation, START, END
from .knowledge.protocol import Document
from .nodes.message import FlowReference
from .memory import Memory
from .history import ConversationHistory
from .logging import info, warning, error, debug, set_log_levels, get_logger
from .models import Model
from .nodes import Node, RemoteNode, LocalNode, LocalNodeProtocol, MailboxProtocol, WorkerProtocol, ContextProtocol
Expand All @@ -12,23 +13,17 @@
from .squads import Squad
from .tools import McpTool, Tool
from .knowledge import (
TextPiece,
SearchHit,
SearchResults,
Knowledge,
SearchableKnowledge,
InMemory,
Database,
KnowledgeProvider,
KnowledgeAggregator,
TextExtractor,
Chunker,
NaiveChunker,
Memory,
Retrieval,
)
from .gather import gather
from .knowledge.memory import Retrieval

from .ockam_in_rust_for_python import Mailbox, McpClient, McpServer

SEARCHABLE = Retrieval.SEARCHABLE
WHOLE = Retrieval.WHOLE

__doc__ = ""
__all__ = [
# from .agents
Expand Down Expand Up @@ -59,8 +54,8 @@
# from .tools
"McpTool",
"Tool",
# from .memory
"Memory",
# from .history
"ConversationHistory",
# from .models
"Model",
# from .nodes
Expand All @@ -80,22 +75,12 @@
"DynamicPlanner",
# from .squads
"Squad",
# from .knowledge
"RemoteManager",
"Node",
"Tool",
"KnowledgeProvider",
"KnowledgeAggregator",
"Knowledge",
"SearchableKnowledge",
"TextPiece",
"SearchHit",
"SearchResults",
"InMemory",
"Database",
"TextExtractor",
"Chunker",
"NaiveChunker",
# from .memory
"Memory",
"Retrieval",
"Document",
"SEARCHABLE",
"WHOLE",
# from .gather
"gather",
]
Loading