Welcome to Hyphae
Please read Get Started with Truffle before continuing with this tutorial.
If you don't have Python 3 installed on your Mac, follow this comprehensive guide to install Python 3 properly.
sudo apt update
sudo apt install -y python3 python3-pip
pip3 install hyphae- Download Python from: https://www.python.org/downloads/
- Install Python following the installer instructions
- Open Command Prompt or PowerShell and run:
pip install hyphaeOnce you have Python 3 installed:
python3 -m venv myenv
source ./myenv/bin/activate
pip3 install hyphaeOpen example_apps/Arxiv/arxiv.py and follow along.
import hyphae # The main SDK
from hyphae.tools.respond_to_user import RespondToUserReturnType
from perplexity import PerplexitySearcher # see perplexity.py
import hyphae.hooks as hooksKey Concept: Hyphae apps are Python classes with decorated methods that become "tools" your Truffle agent can use.
class ArxivApp:
def __init__(self):
self.selected_paper = None # Agent remembers selected paper
self.paper_content = None # Cached content
def has_paper_selected(self) -> bool:
"""Predicate function - controls when tools are available"""
return self.selected_paper is not NoneKey Concept: Predicates control when tools are available, allowing you to have more control over your agents use of available tools.
@hyphae.tool("Search for papers on a specific topic", icon="magnifyingglass")
@hyphae.args(
query="The search query (topic, keywords, or title)",
max_results="Maximum number of results to return"
)
def SearchPapers(self, query: str, max_results: int = 10) -> str:
# Tool implementation here...Key Concept:
@hyphae.tool()makes a method available to your Truffle agent@hyphae.args()describes parameters so your agent knows how to use the tool- Tools return strings that your agent can read and use
-
Search Tools (always available):
SearchPapers()- ArXiv API searchSearchWebPapers()- Perplexity searchSearchExternalPapers()- Semantic Scholar search
-
Selection Tool (changes agent state):
SelectPaper()- Stores paper data inself.selected_paper
-
Analysis Tools (only available after selection):
Researcher()- expert agent on analyzing academic papersGetCurrentPaper()- View selected paper info
@hyphae.tool("Researcher - Discuss the selected paper",
predicate=lambda self: self.has_paper_selected()) # Only available when paper selectedKey Concept: Predicates create conditional tool access, guiding agents through specific workflows.
The app shows three different integration patterns:
- REST API with XML/Atom (ArXiv):
def SearchPapers(self, query: str, max_results: int = 10) -> str:
url = f"http://export.arxiv.org/api/query?search_query=all:{quote(query)}"
response = requests.get(url)
feed = feedparser.parse(response.content) # Parse XML
# Format results as markdown...- REST API with JSON (Semantic Scholar):
def SearchExternalPapers(self, query: str, max_results: int = 10) -> str:
url = "https://api.semanticscholar.org/graph/v1/paper/search"
response = requests.get(url, params=params)
data = response.json() # Parse JSON
# Format results...- Using external models on the cloud (Perplexity):
def SearchWebPapers(self, query: str) -> str:
search_query = f"academic papers research {query}"
return PerplexitySearcher().run(search_query) # Delegate to external modelSee the AskForHelp tool in the Code app for another example of using other models for help:
@hyphae.tool("Researcher - Discuss the selected paper with an expert")
def Researcher(self, question: str, analysis_type: str = "general") -> str:
# Build rich context from selected paper
paper_info = f"""
Paper: {self.selected_paper['title']}
Authors: {', '.join(self.selected_paper['authors'])}
Abstract: {self.selected_paper['abstract']}
"""
# Create research prompt
researcher_prompt = f"""You are an expert researcher.
User has selected this paper: {paper_info}
Answer their question: {question}
Focus on {analysis_type} analysis."""
# Use external model for expert response
return PerplexitySearcher().run(researcher_prompt)For more detailed comments and the complete implementation, see example_apps/Arxiv/arxiv.py.
Now let's build and deploy this app so you can see it in action! Make sure you have hyphae installed and the TruffleOS client installed before proceeding.
git clone https://github.com/deepshard/get-started-with-hyphae.git
cd get-started-with-hyphae/example_apps/ArxivYour app directory contains:
{
"app_uuid": "",
"metadata": {
"name": "Arxiv Research Assistant",
"description": "Truffle agent for searching and analyzing academic papers",
"icon": "arxiv.png"
}
}FROM hyphaehyphae/alpine-python:arm64
RUN pip3 install ddgs python-weather pytrends pandas requests feedparser
COPY arxiv.py /opt/arxiv/arxiv.py
RUN pip3 install hyphae
WORKDIR /opt/arxiv
CMD ["python3", "/opt/arxiv/arxiv.py"]The Python file we just analyzed above.
Helper class for Perplexity Search integration.
# Build the app into a deployable bundle
hyphae build .This creates a .hyphae bundle file containing your containerized app.
# Connect to your Truffle device
hyphae connectOpen your client and click accept. You are now connected. If it fails or the toast goes away, press Ctrl+C and try again.
hyphae upload .Your app will start uploading. Go to your client to see a progress indicator. Fresh app uploading takes some time to upload, but subsequent uploads will be faster since they are cached and only update your app.
Once deployed, users can interact with your ArXiv Research Assistant through the TruffleOS client.
Now that you understand how Hyphae works, let's create your own app! We recommend that you read through our example apps to get more context on more hyphae features.
# Create your new app directory
hyphae create path-to-your-appStart building!
# Build your app
hyphae build .hyphae build path-to-your-app# Build your app
hyphae upload .hyphae upload path-to-your-appJoin our Discord for developer support!
We're currently working on some major improvements to our SDK
Coming soon:
- Proper developer logs
- Integration with our VSCode extension to make the process of building, testing, and deploying apps CLI free
Happy building!

