File size: 8,433 Bytes
468625b
 
 
 
 
 
 
 
9b5b26a
 
c19d193
8fe992b
468625b
9b5b26a
 
 
468625b
 
 
9b5b26a
 
468625b
 
 
9b5b26a
468625b
 
9b5b26a
468625b
9b5b26a
 
468625b
 
 
 
 
 
 
9b5b26a
468625b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c01ffb
468625b
8c01ffb
468625b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6aae614
ae7a494
 
468625b
 
 
 
 
 
 
 
13d500a
8c01ffb
 
468625b
 
 
 
 
 
 
8c01ffb
468625b
 
 
 
 
861422e
468625b
 
 
 
 
8c01ffb
8fe992b
468625b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c01ffb
 
 
468625b
 
 
 
 
 
 
 
861422e
8fe992b
 
9b5b26a
468625b
 
 
8c01ffb
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
from smolagents import (
    CodeAgent,
    DuckDuckGoSearchTool,
    InferenceClientModel,
    load_tool,
    tool
)

import datetime
import pytz
import yaml

from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI


# ---------------------------------------------------------
# CUSTOM TOOL 1: Current time
# ---------------------------------------------------------
@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """
    Gets the current local date and time for a timezone.

    Args:
        timezone: Valid timezone such as America/New_York,
                  Europe/London, or Asia/Kolkata.
    """

    try:
        tz = pytz.timezone(timezone)

        local_time = datetime.datetime.now(tz).strftime(
            "%Y-%m-%d %H:%M:%S"
        )

        return f"The current local time in {timezone} is {local_time}"

    except Exception as e:
        return f"Could not get time for {timezone}: {str(e)}"


# ---------------------------------------------------------
# CUSTOM TOOL 2: AI technology impact analyzer
# ---------------------------------------------------------
@tool
def analyze_ai_technology(topic: str) -> str:
    """
    Gives a quick engineering impact analysis for common AI technologies.

    Args:
        topic: AI technology or concept such as MCP, RAG,
               LangGraph, vector database, agents, or embeddings.
    """

    technologies = {
        "mcp": {
            "name": "Model Context Protocol (MCP)",
            "impact": 90,
            "description":
                "A standard protocol for connecting AI applications "
                "to tools, APIs, services, and external data.",
            "use_case":
                "Let an AI agent access GitHub, databases, files, "
                "Slack, APIs, and enterprise systems."
        },

        "rag": {
            "name": "Retrieval-Augmented Generation (RAG)",
            "impact": 88,
            "description":
                "Retrieves relevant information before asking an LLM "
                "to generate an answer.",
            "use_case":
                "Enterprise search, documentation assistants, "
                "knowledge bots, and support systems."
        },

        "langgraph": {
            "name": "LangGraph",
            "impact": 82,
            "description":
                "Framework for building stateful and multi-step "
                "LLM workflows and agents.",
            "use_case":
                "Agent orchestration, approval workflows, "
                "multi-agent systems, and long-running AI tasks."
        },

        "vector database": {
            "name": "Vector Database",
            "impact": 80,
            "description":
                "Stores embeddings and performs semantic similarity search.",
            "use_case":
                "RAG, recommendation systems, semantic search, "
                "and AI memory."
        },

        "embeddings": {
            "name": "Embeddings",
            "impact": 78,
            "description":
                "Numeric representations of text, images, or other data "
                "that capture semantic meaning.",
            "use_case":
                "Similarity search, clustering, recommendations, and RAG."
        },

        "agents": {
            "name": "AI Agents",
            "impact": 92,
            "description":
                "LLM-powered systems that can reason about a task "
                "and decide which tools or actions to execute.",
            "use_case":
                "Coding assistants, research agents, workflow automation, "
                "customer support, and enterprise automation."
        }
    }

    key = topic.lower().strip()

    # Handle a few common variations
    aliases = {
        "agent": "agents",
        "ai agent": "agents",
        "ai agents": "agents",
        "model context protocol": "mcp",
        "retrieval augmented generation": "rag",
        "vector db": "vector database",
        "vectors": "vector database",
        "embedding": "embeddings"
    }

    key = aliases.get(key, key)

    if key not in technologies:
        return (
            f"I don't have a predefined analysis for '{topic}'. "
            "Use web search to research it instead."
        )

    item = technologies[key]

    return f"""
Technology: {item['name']}
Estimated engineering impact: {item['impact']}%

What it is:
{item['description']}

Typical use case:
{item['use_case']}
"""


# ---------------------------------------------------------
# CUSTOM TOOL 3: Developer recommendation
# ---------------------------------------------------------
@tool
def recommend_ai_learning_topic(current_skill: str) -> str:
    """
    Suggests an AI engineering topic to learn based on a developer's skill.

    Args:
        current_skill: Developer skill such as React, Node.js,
                       Python, backend, cloud, or fullstack.
    """

    skill = current_skill.lower()

    if "react" in skill or "frontend" in skill:
        return (
            "Recommended next topic: AI application development.\n"
            "Learn LLM APIs, streaming responses, tool calling, "
            "AI SDKs, and agent UIs."
        )

    if "node" in skill or "backend" in skill:
        return (
            "Recommended next topic: Agent orchestration.\n"
            "Learn tool calling, MCP, RAG, LangGraph, queues, "
            "and asynchronous AI workflows."
        )

    if "python" in skill:
        return (
            "Recommended next topic: AI agent frameworks.\n"
            "Explore smolagents, LangGraph, PydanticAI, "
            "RAG pipelines, and evaluation."
        )

    if "cloud" in skill or "aws" in skill:
        return (
            "Recommended next topic: AI platform engineering.\n"
            "Learn model gateways, vector databases, observability, "
            "guardrails, GPU inference, and MCP servers."
        )

    if "fullstack" in skill:
        return (
            "Recommended path:\n"
            "1. LLM APIs\n"
            "2. Structured outputs\n"
            "3. Tool calling\n"
            "4. RAG\n"
            "5. MCP\n"
            "6. LangGraph\n"
            "7. Agent evaluation and observability"
        )

    return (
        "Start with LLM APIs, prompt engineering, structured outputs, "
        "tool calling, RAG, and then AI agents."
    )


# ---------------------------------------------------------
# FINAL ANSWER TOOL
# ---------------------------------------------------------
final_answer = FinalAnswerTool()


# ---------------------------------------------------------
# MODEL
# ---------------------------------------------------------
model = InferenceClientModel(
    max_tokens=2096,
    temperature=0.5,
    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
    custom_role_conversions=None,
)


# ---------------------------------------------------------
# TOOL FROM HUGGING FACE HUB
# ---------------------------------------------------------
image_generation_tool = load_tool(
    "agents-course/text-to-image",
    trust_remote_code=True
)


# ---------------------------------------------------------
# LOAD SYSTEM PROMPTS
# ---------------------------------------------------------
with open("prompts.yaml", "r") as stream:
    prompt_templates = yaml.safe_load(stream)


# ---------------------------------------------------------
# CREATE AGENT
# ---------------------------------------------------------
agent = CodeAgent(
    model=model,

    tools=[
        # Search current information from the web
        DuckDuckGoSearchTool(),

        # Custom tools
        get_current_time_in_timezone,
        analyze_ai_technology,
        recommend_ai_learning_topic,

        # Hugging Face Hub tool
        image_generation_tool,

        # Required final-answer tool
        final_answer,
    ],

    max_steps=8,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name="AI Developer Assistant",

    description=(
        "An AI engineering assistant that can search the web, "
        "analyze AI technologies, recommend learning topics, "
        "check world times, and generate images."
    ),

    prompt_templates=prompt_templates
)


# ---------------------------------------------------------
# START GRADIO UI
# ---------------------------------------------------------
GradioUI(agent).launch()