-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_chat_agent.py
More file actions
73 lines (60 loc) · 1.96 KB
/
test_chat_agent.py
File metadata and controls
73 lines (60 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Test script for the ChatAgent.
This script initializes a ChatAgent and tests basic functionality.
"""
import asyncio
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Check for Gemini API Key
gemini_api_key = os.getenv("GEMINI_API_KEY")
if not gemini_api_key:
print("ERROR: GEMINI_API_KEY environment variable not set.")
print("Please set it in a .env file or in your environment.")
exit(1)
else:
print("GEMINI_API_KEY found.")
# Import after checking for API key
from src.agentic_kernel.agents.chat_agent import ChatAgent
from src.agentic_kernel.config import ConfigLoader, AgentConfig, LLMMapping
# Initialize configuration
config_loader = ConfigLoader()
# Create agent config
agent_config = AgentConfig(
name="test_chat",
type="ChatAgent",
description="Test chat agent",
llm_mapping=LLMMapping(
model="gemini-1.5-flash",
endpoint="gemini",
temperature=0.7,
max_tokens=2000,
),
)
# Initialize chat agent
print("Initializing ChatAgent...")
agent = ChatAgent(
config=agent_config,
config_loader=config_loader,
)
print("ChatAgent initialized successfully.")
# Test get_capabilities
print("\nTesting get_capabilities():")
capabilities = agent.get_capabilities()
print(f"Agent type: {capabilities['type']}")
print(f"Supported tasks: {list(capabilities['supported_tasks'].keys())}")
# Test chat functionality
async def test_chat():
print("\nTesting chat functionality:")
print("Sending message: 'Hello, how are you?'")
response_chunks = []
async for chunk in agent.handle_message("Hello, how are you?"):
response_chunks.append(chunk)
print(f"Received chunk: {chunk}")
complete_response = "".join(response_chunks)
print(f"\nComplete response: {complete_response}")
# Run the async test
if __name__ == "__main__":
print("\nRunning chat test...")
asyncio.run(test_chat())
print("\nTest completed successfully.")