Spaces:
Sleeping
Sleeping
08.09.2025
Browse filesFiles changed (2)
- app.py+3-2
- statefulagent.py+11-8
1 unmodified line2345567823 unmodified lines3233343535363738391 unmodified lineimport gradio as grimport requestsimport pandas as pdfrom statefulagent import AG_Agentfrom statefulagent import StatefulAgent
# (Keep Constants as is)# --- Constants ---23 unmodified lines
# 1. Instantiate Agent ( modify this part to create your agent) try: # agent = StatefulAgent('meta-llama/Llama-3.3-70B-Instruct') agent = AG_Agent() agent = StatefulAgent() except Exception as e: print(f"Error instantiating agent: {e}") return f"Error initializing agent: {e}", None1 unmodified line2345656788910113 unmodified lines151617181920212122222324252627282929303132333435363736383940414240434445461 unmodified linefrom smolagents import CodeAgent, InferenceClientModelfrom a_tools import search_tool, final_answer, image_generation_tool
class AG_Agent: def __init__(self):class StatefulAgent: def __init__(self, model_id = 'Qwen/Qwen2.5-Coder-32B-Instruct', context_len = 0): a_model = InferenceClientModel( model_id='meta-llama/Llama-3.3-70B-Instruct', model_id=model_id, max_tokens=1024, api_key=os.environ.get("HF_API_KEY"), )3 unmodified lines model=self.model, stream_outputs=True, code_block_tags="markdown", use_structured_outputs_internally=True, additional_authorized_imports=['requests', 'bs4','pandas','numpy', 'json','datetime','geopandas','shapely']) self.context = [] self.max_context_len = 20 self.max_steps = 15 self.max_context_len = context_len self.max_steps = 20
def ask(self, question): # Refresh context and add it to prompt self.context.append({"role": "user", "content": question}) if len(self.context) > self.max_context_len: self.context = self.context[-self.max_context_len:] # Combine story for prompt (optional) # Combine history for prompt (optional) prompt = "" for msg in self.context: if msg["role"] == "user": prompt += f"User: {msg['content']}\n" else: prompt += f"Agent: {msg['content']}\n" if self.max_steps > 0: prompt += f"User: {question}\nAgent:" prompt += f"User: {question}\nAgent:" # Run agent with created prompt response = self.agent.run(prompt, max_steps=self.max_steps) # Add answer to history for context if self.max_steps > 0: self.context.append({"role": "assistant", "content": response}) self.context.append({"role": "assistant", "content": response}) if len(self.context) > self.max_context_len: self.context = self.context[-self.max_context_len:] return responseapp.py+3-2
statefulagent.py+11-8