feat: added rich
This commit is contained in:
39
main.py
39
main.py
@@ -1,13 +1,42 @@
|
||||
from core.agent.agent import create_agent_graph
|
||||
from langchain_core.messages import HumanMessage, AIMessage
|
||||
from rich.console import Console
|
||||
from rich.prompt import Prompt
|
||||
from rich.panel import Panel
|
||||
|
||||
AGENT_NAME = "oss-agent"
|
||||
console = Console()
|
||||
|
||||
def main():
|
||||
print("Hello from oss-agent!")
|
||||
console.print(Panel.fit(f"[bold cyan]Hello from {AGENT_NAME}![/bold cyan]", border_style="cyan"))
|
||||
graph = create_agent_graph()
|
||||
graph.invoke({"messages": []})
|
||||
# Invoke the graph with a test message
|
||||
output = graph.invoke({"messages": [HumanMessage(content="hi!")]})
|
||||
print("Agent response:", output)
|
||||
|
||||
# A checkpointer requires a thread ID to track the conversation
|
||||
config = {"configurable": {"thread_id": "1"}}
|
||||
|
||||
user_input = "summarize current directory for me, tell me what does this project do and save summary to summary.txt"
|
||||
console.print(f"\n[bold green]👤 User:[/bold green] {user_input}")
|
||||
state_input = {"messages": [HumanMessage(content=user_input)]}
|
||||
|
||||
while True:
|
||||
for event in graph.stream(state_input, config, stream_mode="updates"):
|
||||
pass
|
||||
|
||||
state = graph.get_state(config)
|
||||
if not state.next:
|
||||
break
|
||||
|
||||
if "get_human_feedback" in state.next:
|
||||
feedback = Prompt.ask("\n[bold yellow]👉 Your response[/bold yellow]")
|
||||
state_input = {"messages": [HumanMessage(content=feedback)]}
|
||||
else:
|
||||
state_input = None
|
||||
|
||||
|
||||
def print_message(message):
|
||||
if message.type == "ai":
|
||||
console.print(f"[bold blue]{AGENT_NAME}:[/bold blue] {message.content}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user