Skip to content

karin-afk/assistant

Repository files navigation

Crypto Portfolio Advisor Assistant

This project is a LangGraph-based conversational assistant designed to help users make short-term decisions about their cryptocurrency portfolio. It combines LLM-powered reasoning with tool integrations for real-time crypto news retrieval, cost management of token use, and optional conversation memory storage in SQLite.


🚀 Features

  • Portfolio Advice: Uses ChatOpenAI (gpt-4o) to provide guidance on short-term portfolio actions.
  • Crypto News Tool: Fetches the latest cryptocurrency news from trusted sources via the Tavily API.
  • Conversation Summarization: Summarizes long conversations to keep context and cost manageable.
  • Optional Memory: Persist state and summaries using a local SQLite database.
  • LangGraph Workflow:
    • assistant → Handles user queries and portfolio advice.
    • tools → Fetches crypto news when needed.
    • summarise_conversation → Periodically summarizes the dialogue to reduce context length.

📦 Installation

  1. Clone this repository:
    git clone <your-repo-url>
    cd <your-repo-name>
    
  2. Create and activate a Python virtual environment:

python -m venv .venv source .venv/bin/activate # macOS/Linux .venv\Scripts\activate # Windows

  1. Install dependencies:

pip install -r requirements.txt

Example requirements.txt:

langchain-openai langchain-core langgraph requests


🔑 Environment Variables

You’ll need to set the following environment variables in a .env file:

OPENAI_API_KEY – your OpenAI API key (for ChatOpenAI).

TAVILY_API_KEY – your Tavily API key (for crypto news retrieval).

See also the .env_example file for the other variables that must be set.


🛠 Usage

Run the assistant by importing the graph in your Python session or script:

from assistant import graph, State

Example interaction

state = State(messages=[])
output = graph.invoke(state)
print(output)

The assistant will:

  • Take the user’s portfolio as input.
  • Retrieve crypto news (via Tavily API).
  • Provide short-term advice based on the combination of portfolio and news.
  • Summarise conversation history if it is too long to manage token costs.
  • Optionally, save conversation history if memory is enabled.

See the testing_assistant.py script for further examples.


🧠 Memory (Optional)

If you set with_memory = True in assistant.py, the assistant will store state and conversation summaries in a local SQLite database.

Default location: ./state_db/example.db

Database is created automatically if it doesn’t exist.


📂 Project Structure

assistant.py         # Main assistant code
state_db/            # (Optional) Folder for SQLite memory
requirements.txt     # Python dependencies
README.md            # Project documentation
testing_assistant.py # Examples of how to use the assistant
other_tools.py       # Other tools in the process of being developed
query_db.py          # Examples of how to query the database to check past conversations
studio/              # Everything required to deploy LangGraph Studio

🚀 Using LanGraph Studio and API

  • LangGraph Studio is a custom IDE for viewing and testing agents.
  • Studio can be run locally and opened in your browser on Mac, Windows, and Linux.
  • Graphs for LangGraph Studio are in the studio/ folder.
  • To start the local development server, run the following command in your terminal in the /studio directory:
langgraph dev

You should see the following output:

- 🚀 API: http://127.0.0.1:2024
- 🎨 Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
- 📚 API Docs: http://127.0.0.1:2024/docs

Open your browser and navigate to the Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024.


🤓 Topics of Learning

I created this assistant to learn the following concepts of LangGraph:

  • Agent
  • State (multiple states, reducers)
  • Memory (checkpoints, external)
  • Summarisation
  • Humman-in-the-loop (streaming, (breakpoints, edit state (not implemented))
  • Controlability (parallelisation, subgraphs, map-reduce) >> not yet implemented.
  • Observability

🔮 Roadmap

  • Parallelise Tavily calls when the LLM decides to search for information about multiple coins.
  • Use multiple tools (e.g. a tool that downloads the past performance of a coin, makes a forcast or set of forecasts, and the LLM uses that in addition to the internet search to make a recommendation).
  • Traceability and observability with LangSmith.

⚠## ️ Disclaimer

This assistant provides educational and informational guidance only. It is not financial advice. Always do your own research before making investment decisions.

About

Set up LangSmith, LangChain and LangStudio

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages