Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions examples/lead-agent/backend-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tower_http::cors::{CorsLayer, AllowOrigin};

// RunAgent configuration
const RUNAGENT_ID: &str = "93eaf000-0000-0000-0000-000000000000";

// Request/Response types
#[derive(Deserialize)]
struct ScoreLeadsRequest {
agent_id: String,
#[serde(default)]
agent_id: Option<String>, // Deprecated: kept for backward compatibility but ignored
candidates: Vec<Value>,
#[serde(default)]
top_n: Option<u32>,
Expand All @@ -26,7 +30,8 @@ struct ScoreLeadsRequest {

#[derive(Deserialize)]
struct ScoreSingleRequest {
agent_id: String,
#[serde(default)]
agent_id: Option<String>, // Deprecated: kept for backward compatibility but ignored
#[serde(default)]
candidate_id: Option<String>,
name: String,
Expand Down Expand Up @@ -60,16 +65,6 @@ async fn score_leads(
Json(request): Json<ScoreLeadsRequest>,
) -> Result<JsonResponse<Value>, (StatusCode, JsonResponse<ErrorResponse>)> {
// Validate required fields
if request.agent_id.is_empty() {
return Err((
StatusCode::BAD_REQUEST,
JsonResponse(ErrorResponse {
error: "agent_id is required".to_string(),
traceback: None,
}),
));
}

if request.candidates.is_empty() {
return Err((
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -111,9 +106,9 @@ async fn score_leads(
println!("[DEBUG] First candidate sample: {}", serde_json::to_string(first).unwrap_or_default());
}

// Initialize RunAgent client
// Initialize RunAgent client using configured agent ID
let client = match runagent::client::RunAgentClient::new(
&request.agent_id,
RUNAGENT_ID,
"lead_score_flow",
false, // Set to false when using RunAgent Cloud
)
Expand Down Expand Up @@ -195,16 +190,6 @@ async fn score_single(
Json(request): Json<ScoreSingleRequest>,
) -> Result<JsonResponse<Value>, (StatusCode, JsonResponse<ErrorResponse>)> {
// Validate required fields
if request.agent_id.is_empty() {
return Err((
StatusCode::BAD_REQUEST,
JsonResponse(ErrorResponse {
error: "agent_id is required".to_string(),
traceback: None,
}),
));
}

if request.name.is_empty() {
return Err((
StatusCode::BAD_REQUEST,
Expand All @@ -225,9 +210,9 @@ async fn score_single(
));
}

// Initialize RunAgent client
// Initialize RunAgent client using configured agent ID
let client = match runagent::client::RunAgentClient::new(
&request.agent_id,
RUNAGENT_ID,
"score_candidate",
true, // local = true for single candidate scoring
)
Expand Down Expand Up @@ -294,9 +279,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup CORS - matching Flask backend origins
let allowed_origins = vec![
"http://localhost:5173",
"http://localhost:5174",
"http://127.0.0.1:5173",
"http://127.0.0.1:5174",
"http://10.1.0.5:5173",
"http://10.1.0.5:5174",
"http://20.84.81.110:5173",
"http://20.84.81.110:5174",
]
.into_iter()
.map(|s| HeaderValue::from_static(s))
Expand Down
22 changes: 2 additions & 20 deletions examples/lead-agent/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ interface CSVMapping {

function App() {
const [step, setStep] = useState<'config' | 'upload' | 'mapping' | 'processing' | 'results'>('config');
const [agentId, setAgentId] = useState('');
const [jobDescription, setJobDescription] = useState('');
const [topN, setTopN] = useState(3);
const [candidates, setCandidates] = useState<Candidate[]>([]);
Expand Down Expand Up @@ -160,13 +159,12 @@ function App() {
setError(null);

try {
const response = await fetch('http://localhost:8000/api/score-leads', {
const response = await fetch('/api/score-leads', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
agent_id: agentId,
candidates: candidateList,
job_description: jobDescription,
top_n: topN,
Expand Down Expand Up @@ -281,22 +279,6 @@ function App() {
</h2>

<div className="space-y-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
RunAgent Agent ID *
</label>
<input
type="text"
value={agentId}
onChange={(e) => setAgentId(e.target.value)}
placeholder="Enter your deployed agent ID"
className="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent"
/>
<p className="mt-1 text-sm text-gray-500">
Get this from running: <code className="bg-gray-100 px-2 py-1 rounded">runagent serve .</code>
</p>
</div>

<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Job Description *
Expand Down Expand Up @@ -326,7 +308,7 @@ function App() {

<button
onClick={() => setStep('upload')}
disabled={!agentId || !jobDescription}
disabled={!jobDescription}
className="w-full bg-blue-600 text-white py-3 rounded-md hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed font-medium transition-colors flex items-center justify-center"
>
Continue to Upload Candidates
Expand Down
2 changes: 1 addition & 1 deletion examples/lead-agent/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
server: {
host: '0.0.0.0', // Listen on all network interfaces
port: 5173,
strictPort: true,
strictPort: false, // Allow fallback to next available port (e.g., 5174)
proxy: {
'/api': {
target: 'http://localhost:8000',
Expand Down